java.lang.NoClassDefFoundError

M

MS

Hi,

When running my app from within NetBeans it works perfectly but when I
start the dist jar version (all up to date) I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: FilmGUI/jar

'java' is in the classpath and the same thing happens regardless of
whether I use the jre or jdk version of java.exe (OS: Win 2000 Pro, JDK
1.5.0.01, JRE 1.5.0.01, NetBeans 4.0).

Strangely if I run the dist jar file from the command line I get the error
specified but I also have a shortcut on my desktop to the jar file in
question and if I launch that with a double-click it runs with all the
functionality working ok except it doesn't 'externally launch my default
browser with a specific URL'. My project compiling sources has Browser.jar
added to it which contains Neosoft's Browser class (which will launch the
system default browser with an URL). Could the Browser class be somehow
not making it into the dist and then causing the error?

Thanks,

MS
 
J

John McGrath

When running my app from within NetBeans it works perfectly but when I
start the dist jar version (all up to date) I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: FilmGUI/jar

'java' is in the classpath and the same thing happens regardless of
whether I use the jre or jdk version of java.exe (OS: Win 2000 Pro, JDK
1.5.0.01, JRE 1.5.0.01, NetBeans 4.0).

Strangely if I run the dist jar file from the command line I get the
error specified but I also have a shortcut on my desktop to the jar file
in question and if I launch that with a double-click it runs with all
the functionality working ok ...

Then perhaps there is something wrong with the command line you are using.
Pity you did not include it in your message.
except it doesn't 'externally launch my default browser with a specific
URL'. My project compiling sources has Browser.jar added to it which
contains Neosoft's Browser class (which will launch the system default
browser with an URL). Could the Browser class be somehow not making it
into the dist and then causing the error?

That is certainly a possibility. Have you looked at the JAR file contents
to see if it is there?
 
M

MS

except it doesn't 'externally launch my default browser with a specific
That is certainly a possibility. Have you looked at the JAR file contents
to see if it is there?

Thanks John.

No I hadn't looked -- now I have and it is not there. I can't seem to work
out how to make sure it gets added. Can you help?

Thanks and Regards,

MS
 
T

Tor Iver Wilhelmsen

MS said:
Exception in thread "main" java.lang.NoClassDefFoundError: FilmGUI/jar

This indicates you typed

java FilmGUI.jar

instead of either

java -jar FilmGUI.jar

or

java -classpath FilmGUI.jar some.MainClass
 
J

John McGrath

No I hadn't looked -- now I have and it is not there. I can't seem to
work out how to make sure it gets added. Can you help?

I don't use NetBeans, so I cannot provide a lot of help in creating the
JAR file. However, I think you have two choices: Either you store all of
the third-party classes (e.g. Browser) in the JAR file itself, or you
place a directive in the JAR file to include another JAR on your classpath.

It sounds like you are building your JAR file using your IDE, so how you
would include the third-party classes in it depends on NetBeans. I
presume that you have somehow told NetBeans about the third-party classes,
and that it was including it them on your classpath when you ran the
program from within NetBeans. The IDE I use (JBuilder) has an "Archive
Builder" facility which presents the list of third party libraries and
allows you to chooses whether to include them with a simple combo box. I
do not know if NetBeans has something similar.

The other choice is to add a "Class-Path" entry in the manifest of the JAR
that you create, and include the third-party classes, usually in a
separate JAR file, along with your application JAR. Again, how you would
do that depends on the tool you are using to create the JAR file.

Of course, all of this can be done with a text editor and the "jar" tool
that comes with the Sun JDK, or with a tool such as "Ant". Such tools are
usually more flexible, but perhaps not as easy to use. IDE tools tend to
make it easier to do the more commonplace tasks.
 
M

MS

Many thanks for your detailed response John.
I don't use NetBeans, so I cannot provide a lot of help in creating the
JAR file. However, I think you have two choices: Either you store all of
the third-party classes (e.g. Browser) in the JAR file itself, or you
place a directive in the JAR file to include another JAR on your classpath.
Ok.


It sounds like you are building your JAR file using your IDE, so how you
would include the third-party classes in it depends on NetBeans. I
presume that you have somehow told NetBeans about the third-party classes,
and that it was including it them on your classpath when you ran the
program from within NetBeans. The IDE I use (JBuilder) has an "Archive
Builder" facility which presents the list of third party libraries and
allows you to chooses whether to include them with a simple combo box. I
do not know if NetBeans has something similar.

Yes, I've added the jar file to the compiling sources. But I can't find
how to add the 3rd party classes to my achive. Surely this is possible in
the IDE! The netbeans help seems to say all I need do is what I've done,
so either it's wrong or -more likely- I've missed something.

The other choice is to add a "Class-Path" entry in the manifest of the JAR
that you create, and include the third-party classes, usually in a
separate JAR file, along with your application JAR. Again, how you would
do that depends on the tool you are using to create the JAR file.

Of course, all of this can be done with a text editor and the "jar" tool
that comes with the Sun JDK, or with a tool such as "Ant". Such tools are
usually more flexible, but perhaps not as easy to use. IDE tools tend to
make it easier to do the more commonplace tasks.

Understood and thanks.

I've found a netbeans mailing list and have emailed that, as it will be
useful to know how to do this from the IDE.

Cheers,

MS
 
M

MS

Thanks Tor.

What you say is true, however the problem with browser.jar -as discussed
with John- remains. It's just a question of when the exception is thrown
or 'displayed' -- immediately displayed with 'java FilmGUI.jar' or thrown
when the method using the openUrl() (held in browser.jar) is run if using
'java -jar FilmGUI.jar'.

Cheers,

MS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,075
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top