You are not logged in.

#1 2009-05-20 17:27:09

daJense
Member
Registered: 2009-05-17
Posts: 45

setting java classpath [SOLVED]

Hi everybody,
I am sure this is not hard, but I have been looking for some time now and just couldn't figure out how to do it. Trying to run simple java applications (I am just learning...) I allways get this error

Exception in thread "main" java.lang.NoClassDefFoundError: /opt/java/jre/bin/
Caused by: java.lang.ClassNotFoundException: .opt.java.jre.bin.
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)

So after doing some research I am pretty sure this is because my classpath is not set, but I can't figure out the correct directory. I assumed this would be

/opt/java/bin

So I added these lines to my .basrc

export PATH=/opt/java/bin:$PATH
export JAVA_HOME="/opt/java/"
export CLASSPATH=.:/opt/java/

I think java is installed just fine, cause I can run eclipse without problems..
But it doesn't work... so please help me :)

Last edited by daJense (2009-05-25 14:10:49)

Offline

#2 2009-05-25 04:46:15

arch777
Member
Registered: 2009-05-24
Posts: 8

Re: setting java classpath [SOLVED]

If you install jre from repos, I think java is in the path.
Try run this to see java in your system path:

echo $PATH

Offline

#3 2009-05-25 13:36:20

Garns
Member
Registered: 2008-05-28
Posts: 239

Re: setting java classpath [SOLVED]

Java should be able to find and load the classes in the standard library on its own, without you explicitly specifying their location. If you want to use any other libraries you have to either set the CLASSPATH variable or use the -cp argument when invoking the VM.

Your error looks somewhat strange, can you post the command you use when you try to start applications and maybe the code of something you try to start?

Offline

#4 2009-05-25 14:02:08

daJense
Member
Registered: 2009-05-17
Posts: 45

Re: setting java classpath [SOLVED]

First, Thx for replying.. so here is what I get using echo

[jens@jense-mobile Kap02]$ echo $PATH
/opt/java/bin:/opt/java/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/share/eclipse:/opt/java/bin:/opt/java/jre/bin:/opt/kde/bin:/usr/share/netbeans/bin/:/usr/bin/perlbin/site:/usr/bin/perlbin/vendor:/usr/bin/perlbin/core:/opt/qt/bin:/home/db2inst1/sqllib/bin:/home/db2inst1/sqllib/adm:/home/db2inst1/sqllib/misc:/home/db2inst1/sqllib/db2tss/bin
[jens@jense-mobile Kap02]$

Now for studying I try to run simple java apps from commandline. Using the -cp option I got my programm to work (it's "HelloWorld"). So if I set up a directory

~/javaapps/

How would I set this path so I don't have to use the -cp option every time I invoke an app
?

Offline

#5 2009-05-25 14:09:11

daJense
Member
Registered: 2009-05-17
Posts: 45

Re: setting java classpath [SOLVED]

Never mind, I solved it. So if anybody else stumbles over this:

Do not execute your java command using the .java extension. Meaning if you try to invoke the command

java HelloWorld.java

it will fail. If you just do

java JHelloWorld

it will work. I feel stupid, but thx for your help, it pointed me in the right direction..

smile

Offline

#6 2009-07-09 18:45:43

Draconiak
Member
Registered: 2009-07-09
Posts: 2

Re: setting java classpath [SOLVED]

for even more noobs that i....
i just install java JRE from aur, but my apps doest run, "java command not found"  then i ran

export PATH=/opt/java/bin:$PATH
export JAVA_HOME="/opt/java/"
export CLASSPATH=.:/opt/java/

classpath in path?, /opt/java is the  path of java, anyway they ran just fine now

Last edited by Draconiak (2009-07-09 18:46:09)

Offline

Board footer

Powered by FluxBB