Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Error executing a .jar file with JDBC SqlServerDriver

2 views
Skip to first unread message

mikel lertxundi via JavaKB.com

unread,
Apr 8, 2005, 6:16:03 AM4/8/05
to
I've a problem executing a .jar file when it invokes the Sql Server Driver.
I've no problem inside the IDE (Eclipse) but when I deploy it to a jar file
and execute it from the console I got this:
(Not to say that I've modified the classpath with the jar libraries of the
driver from Microsoft)
-------------------------------------------------------------------------
java.lang.ClassNotFoundException:
com.microsoft.jdbc.sqlserver.SQLServerDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at csAccesoBD.ActualizarBD(csAccesoBD.java:36)
at Principal$1.actionPerformed(Principal.java:39)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown
Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown
Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown
Sour
ce)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown
Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
------------------------------------------------------------------------
If someone has the key, please tell me.

Thanks

--
Message posted via http://www.javakb.com

Arnaud Berger

unread,
Apr 8, 2005, 6:31:49 AM4/8/05
to
Hi,

Sorry but the classpath IS the problem with such an exception.

What is the exact commands you us on the console ?

Regards,

Arnaud

"mikel lertxundi via JavaKB.com" <fo...@nospam.JavaKB.com> a écrit dans le
message news: 2aed74f682474f8e...@JavaKB.com...

mikel lertxundi via JavaKB.com

unread,
Apr 8, 2005, 6:40:55 AM4/8/05
to
I use java -jar myFile.jar

thanks

mikel lertxundi via JavaKB.com

unread,
Apr 8, 2005, 6:42:45 AM4/8/05
to
Excuse me,

and to set the classpath:

set classpath = pathForJarFile/DriverFile.jar

Arnaud Berger

unread,
Apr 8, 2005, 6:50:47 AM4/8/05
to
Hi,

Try this: java -cp "list of jar paths" -jar myFile.jar

If you are running linux, it may simply be a matter of using "export"
instead of "set"
Also note that CLASSPATH variable is case-sensitive with linux.
Check this with "echo $CLASSPATH" when you're done


Regards,

Arnaud

"mikel lertxundi via JavaKB.com" <fo...@JavaKB.com> a écrit dans le message
news: 5b7867218d5146c0...@JavaKB.com...

Arnaud Berger

unread,
Apr 8, 2005, 6:57:49 AM4/8/05
to
Sorry I'm wondering if the command I told you would work.

I think calling "java -jar" may not take CLASSPATH into account.

So better use :

java nameOfYourMainClass

once your CLASSPATH was correctly set (including myFile.jar)

Regards,

Arnaud

"Arnaud Berger" <a.be...@libertycontact.fr> a écrit dans le message news:
d35nm7$66k$1...@news.tiscali.fr...

Igor Kolomiyets

unread,
Apr 8, 2005, 8:23:58 AM4/8/05
to
Alternatively add the following line into your manifest file:

Class-Path: . jar1.jar jar2.jar jar3.jar

jar1.jar jar2.jar jar3.jar should be located in the same directory where
you're running your application from. "." is redundant if you are not
using any classes or files that aro not bundled into jar files.

Best regards,
Igor.

Arnaud Berger пишет:


> Sorry I'm wondering if the command I told you would work.
>
> I think calling "java -jar" may not take CLASSPATH into account.
>
> So better use :
>
> java nameOfYourMainClass
>
> once your CLASSPATH was correctly set (including myFile.jar)
>
> Regards,
>
> Arnaud
>

> "Arnaud Berger" <a.be...@libertycontact.fr> a Иcrit dans le message news:


> d35nm7$66k$1...@news.tiscali.fr...
>
>>Hi,
>>
>>Try this: java -cp "list of jar paths" -jar myFile.jar
>>
>>If you are running linux, it may simply be a matter of using "export"
>>instead of "set"
>>Also note that CLASSPATH variable is case-sensitive with linux.
>>Check this with "echo $CLASSPATH" when you're done
>>
>>
>>Regards,
>>
>>Arnaud
>>

>>"mikel lertxundi via JavaKB.com" <fo...@JavaKB.com> a Иcrit dans le

mikel lertxundi via JavaKB.com

unread,
Apr 8, 2005, 9:19:41 AM4/8/05
to
I've done all you say with no results, I dont know what to do.

I've try executing the jar file using command java mainclass like this

java mainclass.class

and I have this answer: Exception in thread "main"
java.lang.NoClassDefFoundError: principal/class

so...it doesn't work (or I'm doing it wrong).

Neither the command java -cp "list of jar files" works. I type it like this:

java -cp jarfile1;jarfile2;.. -jar myjarFile.jar

Just one last thing:

In my code I type this:

System.out.println("Class path is really " + System.getProperty
("java.class.path") );

to watch the real classpath that is managing the aplication, and I obtain
that the jar file is really the class path.

Class path is really prueba.jar

where prueba.jar is the jar file that I've develop.

Thanks for all

Mikel

Igor Kolomiyets

unread,
Apr 8, 2005, 9:26:44 AM4/8/05
to
He actually ment here:

java -cp jarfile1;jarfile2;.. mainclass.class

including your own jar file in -cp.

Best regards,
Igor.

mikel lertxundi via JavaKB.com пишет:

mikel lertxundi via JavaKB.com

unread,
Apr 8, 2005, 10:25:18 AM4/8/05
to
Hi,
I did what you say typing,
java -cp jarfile1;jarfile1 MyMainClass.class and I got:

Exception in thread "main" java.lang.NoClassDefFoundError: principal

Mikel

Arnaud Berger

unread,
Apr 8, 2005, 10:35:43 AM4/8/05
to
Hi again ,

1) You shouldn't include the ".class" part, your command should look like :
java -cp jarfile1;jarfile1 MyMainClass

and not


java -cp jarfile1;jarfile1 MyMainClass.class

2)If your class is in a package (say mypackage) , the command would be

java -cp jarfile1;jarfile1 mypackage.MyMainClass

Hope it helps,

Regards,

Arnaud

"mikel lertxundi via JavaKB.com" <fo...@JavaKB.com> a écrit dans le message

news: 5531f3b5028b42b1...@JavaKB.com...

mikel lertxundi via JavaKB.com

unread,
Apr 8, 2005, 11:07:14 AM4/8/05
to
It doesn?t work, i got:

Exception in thread "main" java.lang.NoClassDefFoundError: Principal

Lee Fesperman

unread,
Apr 8, 2005, 2:07:20 PM4/8/05
to
mikel lertxundi via JavaKB.com wrote:
>
> It doesn?t work, i got:
>
> Exception in thread "main" java.lang.NoClassDefFoundError: Principal

I'm sorry that you've gotten some bad advice here. However, you need to post what you
actually enter at the commandline.

Try this first:

java -cp "pathForJarFile/DriverFile.jar;prueba.jar" Principal

Assuming:

+ prueba.jar is in the current directory, otherwise use the proper path.
+ prueba.jar contains Principal.class.
+ 'pathForJarFile' is the path to the driver jar.
+ 'DriverFile.jar' is the jar containing the JDBC driver.
+ 'Principal' is the actual name of your class containing main().
+ The Principal class is not in a package.


Again, please post *exactly* what you are entering at the command line and the results
you get.

--
Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
==============================================================
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)

mikel lertxundi via JavaKB.com

unread,
Apr 11, 2005, 3:58:15 AM4/11/05
to
Thank you very much to all, now it works.

It was a just a f***ing classpath thing

0 new messages