Java and Jar

G

Guest

Hi !

I have a problem with the classpath within the manifest file:

Note: The names are changed due the company policy

I am using MsSQL libraries, and some of my own, which resides in \myjava
directory.
Demo is main class.

If I run java manually:

C:\project>java -cp .;\java\bin;\myjava;\java\lib\msutil.jar;\java\lib
\msbase.jar;\java\lib\mssqlserver.jar;Demo.jar Demo

it works.


If the same JAR file is started with:

C:\project>java -jar Demo.jar

I get

Exception in thread "main" java.lang.NoClassDefFoundError:
myjava/prjname/prjclass

All imports and classes are properly specified (otherwise it would run
as the first example shows)

***

Ok, now my manifest file, which is put in my jar file.
Manifest-Version: 1.0
Created-By: 1.4.2_03 (Sun Microsystems Inc.)
Main-Class: Demo
Class-Path: . \java\bin \myjava
\java\lib\msutil.jar
\java\lib\msbase.jar
\java\lib\mssqlserver.jar

But when I include that manifest with jar command, and examine it in jar
file,
it seems that it breaks lines by himself

I need to cut lines into several lines due the 70 CHARS restriction.
In documentation it says:
Line length:
No line may be longer than 72 bytes (not characters), in its UTF8-
encoded form.
If a value would make the initial line longer than this, it should be
continued
on extra lines (each starting with a single SPACE).

Any hint ?
 
R

Roedy Green

Exception in thread "main" java.lang.NoClassDefFoundError:
myjava/prjname/prjclass

that class file had better be in the jar. Java ignores the SET
classpath or even the command line -cp when using jars.

With JDK 1.5 you can put a Class-Path: (note the odd spelling) in the
jar manifest to tell Java to look outside the jar for some classes.

Alternatively, put your extra jars in the ext directory.

For details see:

http://mindprod.com/jgloss/jar.html
 
G

Guest

look- said:
that class file had better be in the jar. Java ignores the SET
classpath or even the command line -cp when using jars.

With JDK 1.5 you can put a Class-Path: (note the odd spelling) in the
jar manifest to tell Java to look outside the jar for some classes.

Alternatively, put your extra jars in the ext directory.

For details see:

http://mindprod.com/jgloss/jar.html
Cannot believe what was wrong !!!!

The trick is in \java\bin subpath.

When using with -cp command it can be like this

C:\project>java -cp \java\bin Demo

But when using it in a manifest, it must end with ***BACKSLASH*** (or
slash in unix)

Class-Path: \java\bin\


It seems, those Sun's programmers were so lawzy ...
 
R

Raymond DeCampo

Cannot believe what was wrong !!!!

The trick is in \java\bin subpath.

When using with -cp command it can be like this

C:\project>java -cp \java\bin Demo

But when using it in a manifest, it must end with ***BACKSLASH*** (or
slash in unix)

Class-Path: \java\bin\


It seems, those Sun's programmers were so lawzy ...

How very interesting. So you were able to execute your program using
the -jar option and the Class-Path manifest entry. An examination of
the OP reveals that you are using version 1.4.2_03.

So here is further evidence that the information Roedy gave above and is
contained at http://mindprod.com/jgloss/jar.html is incorrect.

Roedy, I respectfully request that you fix the information on your website.

Thanks,
Ray
 
G

Guest

How very interesting. So you were able to execute your program using
the -jar option and the Class-Path manifest entry. An examination of
the OP reveals that you are using version 1.4.2_03.
Yep, 1.4.2_03 version.
 
R

Roedy Green

Roedy, I respectfully request that you fix the information on your website.

I posted the sun bug showing this did not work in 1.3 and they had no
intention of fixing it.

That leaves version 1.4 in contention. Nobody has done an experiment
yet to resolve this or quoted Sun documentation.

I am not about to change things without some more solid evidence the
information I was given earlier is wrong. You are so eager to put me
down you want me hanged before a trial.
 
R

Roedy Green

Yep, 1.4.2_03 version.

Experiments are in order or 1.4 and 1.5 to see if the trailing \ is
needed in both. The necessity for it could easily have been mistaken
that the Class-Path was continuing to be ignored in 1.4.

Does someone have both 1.4 and 1.5 installed to do the checks?
 
R

Roedy Green

Roedy, I respectfully request that you fix the information on your website.

The Class-Path is not fully functional even in 1.5 since all entries
have to be relative.

Eventually it may support both absolute filenames and urls.
 
R

Raymond DeCampo

Roedy said:
Experiments are in order or 1.4 and 1.5 to see if the trailing \ is
needed in both. The necessity for it could easily have been mistaken
that the Class-Path was continuing to be ignored in 1.4.

I do not see how. The point is that it works, and it has always worked.

The whole trailing slash thing is used by whatever routine Sun is
running to distinguish between files and directories. (This may seem
stupid, but I think that the underlying reason is that URLs are used
under the hood. So it fails for the same reason http://abc.orq/music
fails where http://abc.orq/music/ succeeds.)
Does someone have both 1.4 and 1.5 installed to do the checks?

The trailing slash or not has nothing to do with the Class-Path entry in
the manifest being broken. I've already told you it works. I maintain
a development tool written in Java. This tool is executed via this
method. Every day in my company, people use this tool. If it were
broken, I would know about it. We are using 1.4.

I'm not just saying it works, I have seen it work. The OP has seen it
work. Again, I ask you to update your website.

Thanks,
Ray
 
R

Raymond DeCampo

Roedy said:
The Class-Path is not fully functional even in 1.5 since all entries
have to be relative.

Eventually it may support both absolute filenames and urls.

This is irrelevant to issue we are discussing here.

Ray
 
R

Raymond DeCampo

Roedy said:
I posted the sun bug showing this did not work in 1.3 and they had no
intention of fixing it.

I'm trying to be polite as possible, but this is just wrong. The bug
you posted said nothing of the sort. The bug actually recommended using
the functionality you claim is broken.

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4356783

In this bug someone complains about the well-known, documented behavior
that when the -jar option to the JVM executable is used, the CLASSPATH
environment variable and the value of the -cp option are ignored. In
the workaround section, Sun recommends using the Class-Path entry of the
manifest file in order to set the classpath for the JVM.

If we cannot agree that the above is an accurate synopsis of what the
bug report says, then I do not see how we can have a rational discussion
on this issue.
That leaves version 1.4 in contention. Nobody has done an experiment
yet to resolve this or quoted Sun documentation.

I am not about to change things without some more solid evidence the
information I was given earlier is wrong. You are so eager to put me
down you want me hanged before a trial.

Roedy, I do not want you "hanged". I am not interested in some personal
victory where you admit you were wrong, blah blah blah. I'm not even
saying that you are wrong per se, just that there is erroneous
information on your web site. There's bound to be a few mistakes given
the size, it is nothing to be upset over or take personally. The
genesis of the error might be perfectly innocent and I am perfectly
willing to assume it is.

I assume your currently stance is from the confrontational manner in
which I broached the subject, which I regret. I urge you to take a deep
breath and approach it with an open mind. Read the bug report again
without preconceptions.

Here are the links for 1.4 and 1.3 where Sun documents the Class-Path
attribute:

http://java.sun.com/j2se/1.4.2/docs/guide/jar/jar.html
http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html


Ray
 
R

Roedy Green

I'm not just saying it works, I have seen it work.

Finally you offer some evidence it works in 1.4.

I hope you understand why I don't take your word on it.

You seem to be far more interested in putting me down than sorting out
the truth.
 
R

Raymond DeCampo

Roedy said:
Finally you offer some evidence it works in 1.4.

I've said that (what you quoted) from the beginning.
I hope you understand why I don't take your word on it.

You seem to be far more interested in putting me down than sorting out
the truth.

First, realize that I do not need to sort out the truth. I am certain
of what it is already. I understand that you are not.

Second, I have apologized for my aggressive statements. I recognize
that my earlier comments were counter-productive. I am not interested
in putting you down. I just want the inaccuracies on your website
corrected so that others are not misled.

You have not answered my post concerning the bug you posted. (Perhaps
your news server doesn't have it or mine does not have the reply.) I
hope that we could get some common ground there before moving forward.

Ray
 
T

Tor Iver Wilhelmsen

Class-Path: \java\bin\

Note that forward slashes work in Windows as well. Only the command
shells like cmd.exe and command.com have problems with them.
 

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
473,781
Messages
2,569,615
Members
45,296
Latest member
HeikeHolli

Latest Threads

Top