my dog learned polymorphism*
The moose likes Ant, Maven and Other Build Tools and the fly likes [Ant]Does not run java task Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "[Ant]Does not run java task" Watch "[Ant]Does not run java task" New topic
Author

[Ant]Does not run java task

Rafael Afonso
Ranch Hand

Joined: Jul 16, 2002
Posts: 63
Hello:

I have this class:

org.apache.commons.lang.ObjectUtils package comes from Jakarta Commons Lang. This source is in src directory and Commons Lang jar is in lib directory. My buildfile is in root directory and it is:

build and jar target run OK. But when I run runjava target I get this message:

Buildfile: C:\java\eclipse\workspace\testant\build.xml
init:
build:
runjava:
[java] java.lang.NoClassDefFoundError: Teste
[java] Exception in thread "main"
[java] Java Result: 1
BUILD SUCCESSFUL
Total time: 1 second

And runjar target prints this:

Buildfile: C:\java\eclipse\workspace\testant\build.xml
init:
build:
jar:
runjar:
[java] java.lang.NoClassDefFoundError: org/apache/commons/lang/ObjectUtils
[java] at Teste.main(Unknown Source)
[java] Exception in thread "main"
[java] Java Result: 1
BUILD SUCCESSFUL
Total time: 1 second

But if I remove reference to ObjectUtils method:

runjar target runs correctly, but runjava target shows same message.
I it was problem of classpath configuration, I had problems with build target. So my mistake must be in other place, but I know where.

Thanks,


=================================<br /> Rafael U. C. Afonso<br /> <a href="http://www.javafree.com.br" target="_blank" rel="nofollow">www.javafree.com.br</a><br />=================================<br /><i>Where is debug?<br />debug is on the table</i>
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
In your runjava target your class Teste isn't in your classpath.
Rafael Afonso
Ranch Hand

Joined: Jul 16, 2002
Posts: 63
Originally posted by Carol Enderlin:
In your runjava target your class Teste isn't in your classpath.

Ok, I include bin directory in classpath and it works. Build.xml was modified:

It works to runjava task. But my problem with runjar continues.

Thanks,
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Sun's java tools documentation on "java" says about using java's -jar option,

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

So, try adding the Class-Path attribute to the manifest. The classpath it is referring to is relative to the jar, this worked for me using your build.

<attribute name="Class-Path" value="lib/commons-lang-2.0.jar" />
Rafael Afonso
Ranch Hand

Joined: Jul 16, 2002
Posts: 63
Hello:

Ok. Add jar in class path works. My buildfile is below:

But now I have a new doubt. If I had more than a jar file in my classpath. Would I include these files one by one in "Class-Path" attibute?

Thanks,
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
Use nested <fileset>
Define a path under <project> level, it can be used multi-times
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Originally posted by Rafael Afonso:
Hello:

But now I have a new doubt. If I had more than a jar file in my classpath. Would I include these files one by one in "Class-Path" attibute?



Yes, you would need to include each jar. To include multiple jar files in the jar's manifest Class-Path, they should be all on one line separated by a space. FYI, this is a lot easier using ant than doing it on the command-line!

<attribute name="Class-Path" value="lib/commons-lang-2.0.jar lib/another.jar" />
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [Ant]Does not run java task
 
Similar Threads
need help to find the right path to images
Apache Ant add property file and policy file
image is missing when jaring
Build problem when including third party jars in classpath using ant
ant build file-building jar problem