classpath problem in my machine

H

harryos

hi
I have an application that uses some classes in jai which i have kept
in a lib directory.I used this build script to compile and run the
application

<property name="main-class" value="mypack.MyApp"/>
<path id="myclasspath">
<fileset dir="lib" includes="**/*.jar"/>
</path>
<path id="application" location="${dist.dir}/myapp.jar"/>

<target name="compile" depends="init">
<javac srcdir="src" destdir="${classes.dir}"
classpathref="myclasspath"/>
</target>

<target name="run" depends="jar">
<java fork="true" classname="${main-class}">
<classpath>
<path refid="myclasspath"/>
<path refid="application"/>
</classpath>
</java>
</target>
....

when i run ant ,the compile is done without any error.But the run
target causes an error>>
[java] Exception in thread "main" java.lang.NoClassDefFoundError:
javax/media/jai/OperationRegistrySpi

The OperationRegistrySpi.class is present in javax/media/jai in
jai_core.jar in my lib directory.

I am working on a WinXP machine and don't have a CLASSPATH variable in
env variables.All classpath info is supposed to be given in the ant
script.

I moved this application to a fresh machine where jdk and ant are
installed and ran the script.There, my application is running without
any error!!

Can someone help me find out why this is happening in my machine?I
have NetBeans and JEE5 installed in my machine .Is that any reason for
this classpath problem?

thanks
harry
 
J

Jan Thomä

when i run ant ,the compile is done without any error.But the run
target causes an error>>
[java] Exception in thread "main" java.lang.NoClassDefFoundError:
javax/media/jai/OperationRegistrySpi

I moved this application to a fresh machine where jdk and ant are
installed and ran the script.There, my application is running without
any error!!

I wonder if you might have some spaces in the path names where you run
your application (like C:\documents and settings\). This caused some
weird problems here a while ago, so you might want to check that. Have
you put the app into the same folder on both machines?

Best regards,
Jan
 
H

harryos

I wonder if you might have some spaces in the path names where you run your application (like C:\documents and settings\).

No spaces are present in any of the paths..
Also ,I used the -v option to print the classpath when java.exe is
run.When i copy that classpath and use it to run the application from
cmd prompt(like java -classpath ...) it runs without any problems.I
can't figure out why ant behaves like this in one machine alone.

thanks
harry
 
L

Lew

harryos said:
<property name="main-class" value="mypack.MyApp"/>
<path id="myclasspath">
<fileset dir="lib" includes="**/*.jar"/>
</path>
<path id="application" location="${dist.dir}/myapp.jar"/> ....
<target name="run" depends="jar">
<java fork="true" classname="${main-class}">
<classpath>
<path refid="myclasspath"/>
<path refid="application"/>
</classpath>
</java>
</target>
...

when i [sic] run ant ,the compile is done without any error.But the run
target causes an error>>
[java] Exception in thread "main" java.lang.NoClassDefFoundError:
javax/media/jai/OperationRegistrySpi

The OperationRegistrySpi.class is present in javax/media/jai in
jai_core.jar in my lib directory.

I am working on a WinXP machine and don't have a CLASSPATH variable in
env variables.All classpath info is supposed to be given in the ant
script.

I moved this application to a fresh machine where jdk and ant are
installed and ran the script.There, my application is running without
any error!!

Can someone help me find out why this is happening in my machine?I
have NetBeans and JEE5 installed in my machine .Is that any reason for
this classpath problem?

Could it be that it's because running a program from a JAR ignores the outer
world's classpath, and uses only the classpath from its own manifest?

Could it be that the Ant classpath target specifies 'lib/' as a relative
directory, which is absent in the runtime environment?

Some of the subtleties of Ant escape me, so I'm not sure which might apply.
However, given that part of the purpose of a JAR is to run independently of
Ant, you need to ensure that the JAR manifest correctly specifies the path and
that the lib/ directory (or whatever the manifest specifies) is present in the
correction location relative to the JAR.
 
J

John B. Matthews

harryos said:
I wonder if you might have some spaces in the path names where you
run your application (like C:\documents and settings\).

No spaces are present in any of the paths. Also, I used the -v option
to print the classpath when java.exe is run. When copy that
classpath and use it to run the application from cmd prompt (like
java -classpath ...) it runs without any problems. I can't figure
out why ant behaves like this in one machine alone.


In addition to the questions Lew and Jan posed, you might also look for
spurious additions to any of the directories listed in the system
properties java.endorsed.dirs and java.ext.dirs.
 
H

harryos

In addition to the questions Lew and Jan posed, you might also look for spurious additions to any of the directories listed in the system
properties java.endorsed.dirs and java.ext.dirs.


hi John,
I ran a program to print the system properties in my machine
..I found these problems when I checked the directories in Windows
Explorer.

code shows
java.endorsed.dirs=E:\Java\jre1.6.0_05\lib\endorsed

But in Windows Explorer, there is no folder named 'endorsed' within E:
\Java\jre1.6.0_05\lib

code shows
java.ext.dirs=E:\Java\jre1.6.0_05\lib\ext;C:\WINDOWS\Sun\Java\lib\ext

But in Windows Explorer there is no lib\ext within C:\WINDOWS\Sun
\Java .There is only a folder named 'Deployment' (probably from jee5
installation)

Then again,these 2 problems are present in another machine where I did
a fresh installation of JDK and ant.In that machine however,the run
target I mentioned runs without any errors.

I am really confused by this.As a last attempt, I renamed all 'lib'
directories in my application to 'mylib' and made appropriate changes
in the build.xml.Still,the problem persists.

thanks for the replies,
harry
 

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

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top