Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

[Ant]Does not run java task

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your runjava target your class Teste isn't in your classpath.
 
Rafael Afonso
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use nested <fileset>
Define a path under <project> level, it can be used multi-times
 
Carol Enderlin
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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" />
 
Beware the other head of science - it bites! Nibble on this message:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic