Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #24546 > unrolled thread

Exception in thread “main” java.lang.NoClassDefFoundError Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.Task

Started bymorpheous.sigma@gmail.com
First post2013-07-01 00:14 -0700
Last post2013-07-01 17:25 -0700
Articles 4 — 4 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  Exception in thread “main” java.lang.NoClassDefFoundError Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.Task morpheous.sigma@gmail.com - 2013-07-01 00:14 -0700
    Re: Exception in thread “main” java.lang.NoClassDefFoundError Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.Task lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-07-01 09:36 +0100
    Re: Exception in thread “main” java.lang.NoClassDefFoundError Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.Task markspace <markspace@nospam.nospam> - 2013-07-01 09:03 -0700
      Re: Exception in thread “main” java.lang.NoClassDefFoundError Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.Task Lew <lewbloch@gmail.com> - 2013-07-01 17:25 -0700

#24546 — Exception in thread “main” java.lang.NoClassDefFoundError Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.Task

Frommorpheous.sigma@gmail.com
Date2013-07-01 00:14 -0700
SubjectException in thread “main” java.lang.NoClassDefFoundError Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.Task
Message-ID<1c9087e2-3652-4d73-8ef8-f5d3e8c4445f@googlegroups.com>
I am new to Java, although I have several years experience with other langs (e.g. C/C++ etc). I am trying to run an example program, which uses Ant for its build. I have struggled to get rid of the ClassNotFoundException being thrown for the last four days and despite trying various solutions posted elsewhere on the Internet, I have been unable to solve the problem.

I wonder if anyone on here can help.

Here is the stack trace, (as well as my attempts to solve the problem):


$ ./init-og-examples-db.sh
### Creating empty database
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/Task
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.Task
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
... 11 more
Could not find the main class: com.opengamma.util.test.DbTool. Program will exit.
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/Task
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.Task
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
... 11 more
Could not find the main class: com.opengamma.util.test.DbTool. Program will exit.
### Adding example data
Exception in thread "main" java.lang.NoClassDefFoundError: com/opengamma/examples/tool/ExampleDatabasePopulator
Caused by: java.lang.ClassNotFoundException: com.opengamma.examples.tool.ExampleDatabasePopulator
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: com.opengamma.examples.tool.ExampleDatabasePopulator. Program will exit.
### Completed


I am runing on Ubuntu 12.0.4 and my environment settings are as follows:


echo $ANT_HOME
/usr/local/apache-ant-1.9.1
echo $JAVA_HOME
/usr/lib/jvm/java-7-oracle/jre


I have set my CLASSPATH as follows:

export CLASSPATH=$CLASSPATH:/usr/local/apache-ant-1.9.1/etc:/usr/local/apache-ant-1.9.1/lib


Can anyone tell me what I am doing wrong?

[toc] | [next] | [standalone]


#24548

Fromlipska the kat <"nospam at neversurrender dot co dot uk">
Date2013-07-01 09:36 +0100
Message-ID<Rb2dndzhk7sWokzMnZ2dnUVZ8hSdnZ2d@bt.com>
In reply to#24546
On 01/07/13 08:14, morpheous.sigma@gmail.com wrote:
> I am new to Java, although I have several years experience with other langs (e.g. C/C++ etc). I am trying to run an example program, which uses Ant for its build. I have struggled to get rid of the ClassNotFoundException being thrown for the last four days and despite trying various solutions posted elsewhere on the Internet, I have been unable to solve the problem.
>
> I wonder if anyone on here can help.
>
> Here is the stack trace, (as well as my attempts to solve the problem):

Ubuntu 12.04
apache-ant-1.8.4

Firstly, the class org/apache/tools/ant/Task.class
lives in ../lib/ant.jar

You can use jar -tf <filename> to inspect a jar file.

Setting your classpath to /usr/local/apache-ant-1.9.1/lib won't include 
ant.jar, try adding ant.jar to your classpath

/usr/local/apache-ant-1.9.1/lib/ant.jar

I think you may be able to do *.jar but you'd need to test that.

I mostly use Ant in Eclipse these days where it 'just works' but I 
notice that all the jars in apache-ant-1.8.4/lib are explicitly added to 
the ant classpath in the build configuration window thingy in Eclipse.

A quick DuckDuckGo tells me that opengamma is some kind of open source 
risk analysis thing, so I presume you downloaded a jar file[s] ... is 
the jar on your classpath? If not it needs to be.

Strangely enough, the classpath causes a lot of problems to new users so
you might find this useful

http://docs.oracle.com/javase/tutorial/essential/environment/paths.html

You also need to be careful when running builds from shell scripts as a 
new shell will be created that may not have the same environment setup 
as the calling shell.

<snip>

HTH

lipska

-- 
Lipska the Kat©: Troll hunter, sandbox destroyer
and farscape dreamer of Aeryn Sun

[toc] | [prev] | [next] | [standalone]


#24551

Frommarkspace <markspace@nospam.nospam>
Date2013-07-01 09:03 -0700
Message-ID<kqs8u8$v02$1@dont-email.me>
In reply to#24546
On 7/1/2013 12:14 AM, morpheous.sigma@gmail.com wrote:

> export CLASSPATH=$CLASSPATH:/usr/local/apache-ant-1.9.1/etc:/usr/local/apache-ant-1.9.1/lib

This is probably your mistake here.  Despite the similar names, 
CLASSPATH does not work like the PATH environment variables in Unix. 
You have to set the classpath to the actual name of the Jar file you 
want to use, or use a '*' as the final element of the class path to use 
all Jar files in a directory.  Doing neither of those, like you have, 
actually looks for 'lose' .class files in the file hierarchy.

export 
CLASSPATH=$CLASSPATH:/usr/local/apache-ant-1.9.1/etc/*:/usr/local/apache-ant-1.9.1/lib/*

or

export 
CLASSPATH=$CLASSPATH:/usr/local/apache-ant-1.9.1/etc/some-ant.jar:/usr/local/apache-ant-1.9.1/lib/another.jar



[toc] | [prev] | [next] | [standalone]


#24563

FromLew <lewbloch@gmail.com>
Date2013-07-01 17:25 -0700
Message-ID<6cbfd66f-c76f-47a0-a9e3-a4924a6d3a4a@googlegroups.com>
In reply to#24551
markspace wrote:
> morpheous.sigma@gmail.com wrote:
>> export CLASSPATH=$CLASSPATH:/usr/local/apache-ant-1.9.1/etc:/usr/local/apache-ant-1.9.1/lib
> 
> This is probably your mistake here.  Despite the similar names, 
> CLASSPATH does not work like the PATH environment variables in Unix. 

All of which is thoroughly explained in the online Java documentation.

> You have to set the classpath to the actual name of the Jar file you 
> want to use, or use a '*' as the final element of the class path to use 
> all Jar files in a directory.  Doing neither of those, like you have, 
> actually looks for 'lose' .class files in the file hierarchy.

Did you mean "'loose'"?

> export 
> CLASSPATH=$CLASSPATH:/usr/local/apache-ant-1.9.1/etc/*:/usr/local/apache-ant-1.9.1/lib/*
> 
> or
> 
> export 
> CLASSPATH=$CLASSPATH:/usr/local/apache-ant-1.9.1/etc/some-ant.jar:/usr/local/apache-ant-1.9.1/lib/another.jar

OP, do read the documentation as this will give you the full story.

-- 
Lew

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web