Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > NoClassDefFoundError and jars, classpath, and ant newbie question

Reply
Thread Tools

NoClassDefFoundError and jars, classpath, and ant newbie question

 
 
bill turner
Guest
Posts: n/a
 
      07-22-2006
Chris Uppal wrote:
> bill turner wrote:
>
> > Okay. Well, I don't know how it would have one. Nor does it seem to
> > have one. Each line is terminated with CRLF (it is Windows, after all).
> > My manifest looks exactly as above. So, it seems it conforms to spec.
> > Hmmmm...

>
> Just to be sure: is the /last/ line terminated by a CRLF ? Many Windows
> editors (correctly for that platform) treat CRLF as a line /separator/ and
> don't put one at the end of the last line unless you explicitly type <return>.
> The manifest file parser (brokenly. IMO) cannot cope with that, but does not
> issue any kind of error message either.
>
> As far as I can see, that problem still remains in 1.5. If the manifest file
> (the actual one in the archive) lacks a terminating CRLF (or some variant) then
> the launcher's parser will ignore that line silently. The jar creation tool
> seems to have a similar problem and doesn't actually copy the last line of the
> supplied manifest into the jar-ed manifest unless it is terminated (and again
> doesn't report any error). I don't know whether either of those problem could
> be affecting you, but it's worth checking a second time.
>
> -- chris


Yes, it does. See my reply to lordy. I appreciate your jumping in!

 
Reply With Quote
 
 
 
 
lordy
Guest
Posts: n/a
 
      07-22-2006
On 2006-07-21, bill turner <> wrote:
> I have been away from java for awhile and never spent much time with
> it. I am having what is a very basic problem that I have not been able
> to resolve. I am trying to include a jar from one project into the
> classpath of another project. My directory structure is as follows:
>
> src - my source files
> class - my class files
> lib - external jars, zips to be used by this project (currently my jar
> from the other project - util)
> jar - my generated jar file
> make - build.xml and manifest file


[SNIP]

> $JAVA_HOME/bin/java -jar jar/jequire.jar


Another attack vector . Try

EITHER

putting util.jar in the same directory as your application jar file.

OR

ensuring that your Manifest Class-Path has the correct relative path
from your application jar to util.jar

E.g.
Class-Path: lib/util.jar (if lib directory is inside 'jar' directory)
or
Class-Path: ../lib/util.jar (if lib directory is in same directory as
your 'jar' directory)

If thats the fix - sorry about the wild goose chase

Lordy
 
Reply With Quote
 
 
 
 
bill turner
Guest
Posts: n/a
 
      07-22-2006
lordy wrote:
> On 2006-07-21, bill turner <> wrote:
> > I have been away from java for awhile and never spent much time with
> > it. I am having what is a very basic problem that I have not been able
> > to resolve. I am trying to include a jar from one project into the
> > classpath of another project. My directory structure is as follows:
> >
> > src - my source files
> > class - my class files
> > lib - external jars, zips to be used by this project (currently my jar
> > from the other project - util)
> > jar - my generated jar file
> > make - build.xml and manifest file

>
> [SNIP]
>
> > $JAVA_HOME/bin/java -jar jar/jequire.jar

>
> Another attack vector . Try
>
> EITHER
>
> putting util.jar in the same directory as your application jar file.
>
> OR
>
> ensuring that your Manifest Class-Path has the correct relative path
> from your application jar to util.jar
>
> E.g.
> Class-Path: lib/util.jar (if lib directory is inside 'jar' directory)
> or
> Class-Path: ../lib/util.jar (if lib directory is in same directory as
> your 'jar' directory)
>
> If thats the fix - sorry about the wild goose chase
>
> Lordy


Option one does not make sense to me. I do not want to mix my
executable (application) jar with jars imported into the project.

Option two is what I think I already have. The application (executable)
jar contains the util jar. The class path lists util jar without path
information. The application jar has the util jar without class info.
An abbreviated look at the application jar (jequire.jar) looks as
follows when viewed in winzip:

Jequire.class com\changent\jequire
JequireTabs.class com\changent\jequire
Manifest.mf meta-inf\
util.jar

Since the manifest does not specify path info and jequire.jar contains
no path info for util.jar, I do not see why I should change it to do
so. I have no idea to what it should be changed. Can you explain
further?

 
Reply With Quote
 
bill turner
Guest
Posts: n/a
 
      07-22-2006
bill turner wrote:
> lordy wrote:
> > On 2006-07-21, bill turner <> wrote:
> > > I have been away from java for awhile and never spent much time with
> > > it. I am having what is a very basic problem that I have not been able
> > > to resolve. I am trying to include a jar from one project into the
> > > classpath of another project. My directory structure is as follows:
> > >
> > > src - my source files
> > > class - my class files
> > > lib - external jars, zips to be used by this project (currently my jar
> > > from the other project - util)
> > > jar - my generated jar file
> > > make - build.xml and manifest file

> >
> > [SNIP]
> >
> > > $JAVA_HOME/bin/java -jar jar/jequire.jar

> >
> > Another attack vector . Try
> >
> > EITHER
> >
> > putting util.jar in the same directory as your application jar file.
> >
> > OR
> >
> > ensuring that your Manifest Class-Path has the correct relative path
> > from your application jar to util.jar
> >
> > E.g.
> > Class-Path: lib/util.jar (if lib directory is inside 'jar' directory)
> > or
> > Class-Path: ../lib/util.jar (if lib directory is in same directory as
> > your 'jar' directory)
> >
> > If thats the fix - sorry about the wild goose chase
> >
> > Lordy

>
> Option one does not make sense to me. I do not want to mix my
> executable (application) jar with jars imported into the project.
>
> Option two is what I think I already have. The application (executable)
> jar contains the util jar. The class path lists util jar without path
> information. The application jar has the util jar without class info.
> An abbreviated look at the application jar (jequire.jar) looks as
> follows when viewed in winzip:
>
> Jequire.class com\changent\jequire
> JequireTabs.class com\changent\jequire
> Manifest.mf meta-inf\
> util.jar
>
> Since the manifest does not specify path info and jequire.jar contains
> no path info for util.jar, I do not see why I should change it to do
> so. I have no idea to what it should be changed. Can you explain
> further?


I have continued to play. I threw in a display of system properties.
The classpath property id below:
java.class.path=Jequire.jar

Since I state in the manifest that util.jar is in the classpath, and it
is at the top level of Jequire.jar, I am wondering if I am
misunderstanding altogether. Does the Class-Path property define the
run time classpath? If so, why isn't that reflected in the System
java.class.path property? FWIW, I've tried specifying -classpath on the
command line and the system classpath property still comes up as above.
Isn't it possible, when executing a jar, to provide further classpath
info? If not, and the manifest Class-Path property doesn't specify the
run time path, how is it determined when executing a jar and how can
one change it?

 
Reply With Quote
 
bill turner
Guest
Posts: n/a
 
      07-23-2006
lordy wrote:
> On 2006-07-21, bill turner <> wrote:
> > I have been away from java for awhile and never spent much time with
> > it. I am having what is a very basic problem that I have not been able
> > to resolve. I am trying to include a jar from one project into the
> > classpath of another project. My directory structure is as follows:
> >
> > src - my source files
> > class - my class files
> > lib - external jars, zips to be used by this project (currently my jar
> > from the other project - util)
> > jar - my generated jar file
> > make - build.xml and manifest file

>
> [SNIP]
>
> > $JAVA_HOME/bin/java -jar jar/jequire.jar

>
> Another attack vector . Try
>
> EITHER
>
> putting util.jar in the same directory as your application jar file.
>
> OR
>
> ensuring that your Manifest Class-Path has the correct relative path
> from your application jar to util.jar
>
> E.g.
> Class-Path: lib/util.jar (if lib directory is inside 'jar' directory)
> or
> Class-Path: ../lib/util.jar (if lib directory is in same directory as
> your 'jar' directory)
>
> If thats the fix - sorry about the wild goose chase
>
> Lordy


Okay! I got it! Whew! It was as you suggested, i needed to specify the
class path attribute in ant as follows:

<attribute name="Class-Path" value="../lib/util.jar" />

I also made some changes to the shell script, but the above was the
real kicker. I didn't realize that the classpath was for items
*outside* the application jar, that to load classes from a jar packaged
within a jar needed to be done programmatically. I finally came upon
the explanation at
http://java.sun.com/docs/books/tutor...r/downman.html
which states:

"Note: The Class-Path header points to classes or JAR files on the
local file system, not JAR files within the JAR file or classes on the
network. To load classes in JAR files within a JAR file into the class
path, you must write custom code to load those classes. For example, if
MyJar.jar contains another JAR file called MyUtils.jar, you cannot use
the Class-Path header in MyJar.jar's manifest to load classes in
MyUtils.jar into the class path."

You had put me on to the correct solution, I just didn't have enough
knowledge to properly understand your solution.

Thanks again for your help!

 
Reply With Quote
 
lordy
Guest
Posts: n/a
 
      07-23-2006
On 2006-07-22, bill turner <> wrote:
> lordy wrote:
>>
>> [SNIP]
>>
>> > $JAVA_HOME/bin/java -jar jar/jequire.jar

>>
>> Another attack vector . Try
>>
>> EITHER
>>
>> putting util.jar in the same directory as your application jar file.
>>
>> OR
>>
>> ensuring that your Manifest Class-Path has the correct relative path
>> from your application jar to util.jar
>>
>> E.g.
>> Class-Path: lib/util.jar (if lib directory is inside 'jar' directory)
>> or
>> Class-Path: ../lib/util.jar (if lib directory is in same directory as
>> your 'jar' directory)
>>
>> If thats the fix - sorry about the wild goose chase
>>
>> Lordy

>
> Option one does not make sense to me. I do not want to mix my
> executable (application) jar with jars imported into the project.
>
> Option two is what I think I already have. The application (executable)
> jar contains the util jar.



AFAIK you should not have your utils jar inside your main jar. That
sounds more like mixing imported jars than simply having them side by
side in the same directory.

Either have

the files <path>/app.jar <path>/util.jar in you distribution out on the
file system And have "Class-Path: util.jar" in your manifest..

OR (but I havent tried it)

have the files <path>/app.jar and <path>/lib/utils.jar
And have Class-Path: lib/util.jar in your manifest..

But dont embed utils.jar in your main .jar. If you want to put the
util.jar inside you main jar then I think this is worse than having the
two jars in the same directory personally, but I'm not sure if Java can
load your util classes directly. You'd have to read up on it. it makes
it awkward if you want to upgrade your 'utils.jar' at a later point.
Most apps (ant etc) have util jars sitting out on the file system
somewhere, not embedded in their own jar.

When you install your application you should simply have ...

<install-path>/your-app.jar
<install-path>/lib/util.jar
As two separate files.

The Manifest of your main app should then contain Class-Path:lib/util.jar

I suspect.

Lordy
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object (ant/tomcat/spring) courtney.machi@gmail.com Java 0 12-08-2006 07:37 PM
error runing ant in eclipse ant view yihucd@gmail.com Java 1 03-07-2006 08:39 PM
trouble with Hibernate and Ant (probably just Ant) john martin Java 2 04-07-2005 09:27 PM
wondering how i can launch tomcat from ant without ant hanging... Chris Bedford Java 6 12-23-2004 12:41 AM
java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory greg.knaddison@gmail.com Python 1 06-22-2004 10:58 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57