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

Weird JVM Behaviour?

0 views
Skip to first unread message

Jussi Jumppanen

unread,
Oct 8, 2004, 6:05:18 AM10/8/04
to
To all the java guru's out there.

I am quite new to Java, but I have come across something
that I find very strange.

Can anyone offer an explanation for the following:

1) I have a directory with nothing in it but two jar files:

D:\test>dir *.jar
24/09/2002 10:39 AM 2,520 MyLayout.jar
09/10/2004 07:24 AM 21,215 Importer.jar
2 File(s) 23,735 bytes

2) I try to run the Import.jar as follows:

d:\test>java -classpath ".;MyLayout.jar;" -jar Importer.jar

but this fails with this error message:

java.lang.NoClassDefFoundError: com/MyPackage/MyLayout
at MainFrame.creatDialog(Importer.java:452)
at MainFrame.<init>(Importer.java:285)
at Importer.<init>(Importer.java:560)
at Importer.Show(Importer.java:572)
at Importer$1.run(Importer.java:578)

3) I unpack the Importer.jar using:

jar xf Importer.jar

and run the program as such:

java -classpath ".;AbsoluteLayout.jar" Importer

this works fine (so the jars look ok, me thinks).

4) So after five hours of pain trying to figure out why things
not working I finally try this:

d:\test>java -classpath ".;MyLayout.jar;Importer.jar" Importer
d:\test>

and to my suprise it works?

For completeness sake below is the mainfest for importer.jar
file:

Manifest-Version: 1.0
Main-Class: Importer
Specification-Title: "Importer"
Specification-Version: "1.00"
Specification-Vendor: "Xidicone P/L"

So why is this a bug?

Why are these two command lines different?

d:\test>java -classpath ".;MyLayout.jar;Importer.jar" Importer
d:\test>java -classpath ".;MyLayout.jar;" -jar Importer.jar

What is the point of the -jar option if it does not work?

Hoping to learn something :)

Cheers Jussi
http://www.zeusedit.com

Babu Kalakrishnan

unread,
Oct 8, 2004, 7:36:00 AM10/8/04
to
Jussi Jumppanen wrote:
> Why are these two command lines different?
>
> d:\test>java -classpath ".;MyLayout.jar;Importer.jar" Importer
> d:\test>java -classpath ".;MyLayout.jar;" -jar Importer.jar
>
> What is the point of the -jar option if it does not work?
>

If you read the description of the -jar option in the documentation of
the "java" command, you'll notice what the last line says :

<QUOTE>
When you use this option, the JAR file is the source of all user
classes, and other user class path settings are ignored.
</QUOTE>

The jar file provides a way of specifying additional jar files to be
included in the classpath (through the "Class-Path:" attribute in the
manifest file).

BK

Thomas Fritsch

unread,
Oct 8, 2004, 7:47:35 AM10/8/04
to
Jussi Jumppanen schrieb:

> To all the java guru's out there.
>
> I am quite new to Java, but I have come across something
> that I find very strange.
>
> Can anyone offer an explanation for the following:
>
> 1) I have a directory with nothing in it but two jar files:
>
> D:\test>dir *.jar
> 24/09/2002 10:39 AM 2,520 MyLayout.jar
> 09/10/2004 07:24 AM 21,215 Importer.jar
> 2 File(s) 23,735 bytes
>
> 2) I try to run the Import.jar as follows:
>
> d:\test>java -classpath ".;MyLayout.jar;" -jar Importer.jar
>
> but this fails with this error message:
>
> java.lang.NoClassDefFoundError: com/MyPackage/MyLayout
> at MainFrame.creatDialog(Importer.java:452)

...

I remember a very similar question "exec jars w/dependent jars" asked
and answered on 24.Sept.2004 in this group.
http://www.google.de/groups?as_umsgid=HlV4d.76%24Ki1.73%40newsread2.news.atl.earthlink.net

I hope this helps.

--
Thomas<dot>Fritsch<squiggle>ops<dot>de

Jussi Jumppanen

unread,
Oct 11, 2004, 7:29:28 PM10/11/04
to
Babu Kalakrishnan <k.a...@sankya.com> wrote in message news:

> If you read the description of the -jar option in the documentation of
> the "java" command, you'll notice what the last line says :
>
> <QUOTE>
> When you use this option, the JAR file is the source of all user
> classes, and other user class path settings are ignored.
> </QUOTE>

In other words the documentation does not match the USAGE produced
by the java compiler:

java -?
Usage: java [-options] class [args...]
(to execute a class)
or java -jar [-options] jarfile [args...] (***)
(to execute a jar file)

where options include:
-client to select the "client" VM
......... snip ........
-cp -classpath <directories and zip/jar files separated by ;>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
As least to me the (***) line of the usage and the line above
say it should have worked!!!!!

I thought the bug was all my doing which is why it took me such
a long time to get working :(

But next time I will know better :)

Thanks for the feedback.

Jussi Jumppanen
Home Page: http://www.zeusedit.com

0 new messages