We help IT Professionals succeed at work.

Classpath to?

viganothing
viganothing asked
on
974 Views
Last Modified: 2013-11-23
Hello,
I'm tryin to load a simple Hello World on my screen using java.
I'm usin SuSe9.3.
I installed the latest Java and set the path to the new java dir.
Now when i'm tryin to :

vs187210:~/jre1.5.0_06 # java "test"
Exception in thread "main" java.lang.NoClassDefFoundError: test

I know this has something to do with the Classpath..but i'm not sure where to set the path to.

I tried into jre1.5.0_06/bin and lib too.Didn't work!
I installed Java on my home directory.

Also when i'm tryin to export PATH=/path/to/java:${PATH}
On the next login i get the old path ..which is older than the java i installed atm.
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016

Commented:
try

java -classpath . test
Harisha M GEngineer
CERTIFIED EXPERT

Commented:
Hi, class name and file name should be same. Do you have a class called "test" ?

It would be helpful if you post the code

---
Harish
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>Also when i'm tryin to export PATH=/path/to/java:${PATH}

Did you put that in .bashrc (assuming Bash)?
>> java "test"

try it without the quotes.

and it's case sensitive, so Test and test are not the same.
and you should be using the jdk, not the jre.
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>try it without the quotes

shouldn't make any difference

>>and you should be using the jdk, not the jre.

Why?
isn't jre the runtime environment. We use the jdk to develop java applications.

Author

Commented:
Actually i'm tryin to do a hello world so its not neccesary to have a class file.is it?

I tried also testin a class file but still the same error

I tried java test , java Test , java "test" , java "Test"
what else i should try?
you need the class file no matter how small you application is.

did you try what CHEJ suggested, java -cp ./ test ?
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>Actually i'm tryin to do a hello world so its not neccesary to have a class file.is it?

Yes. Only class files can be run by a VM

Author

Commented:
i tried the java -cp . filename.jar

I tried testin it with a classfile but still no diference.
I'm sorry but i'm a newbie maybe i'm just passin a pretty dump step but I need your assistance.
May be that my Classfiles are incorrect ( which i'm 90% sure they are correct ) but can you guys upload me a hello world classfile somewhere which i can test it.

Thanks
CERTIFIED EXPERT
Top Expert 2016

Commented:
Do you *have* a jar file? If so, try

java -jar filename.jar
what does your hello world code look like ?
CERTIFIED EXPERT
Top Expert 2016

Commented:
Run the following thus


java -classpath . Props



http://www.sigma-software.freeserve.co.uk/misc/Props.class

Author

Commented:
CEHJ,
I guess this worked..it shows me some properties

[code]
java.runtime.name=Java(TM) 2 Runtime Environment, Stand...
sun.boot.library.path=/usr/lib/jvm/java-1.4.2-sun-1.4.2.08/...
java.vm.version=1.4.2_08-b03
java.vm.vendor=Sun Microsystems Inc.
java.vendor.url=http://java.sun.com/
path.separator=:
java.vm.name=Java HotSpot(TM) Client VM
file.encoding.pkg=sun.io
user.country=US
sun.os.patch.level=unknown
java.vm.specification.name=Java Virtual Machine Specification
user.dir=/home/l2j
java.runtime.version=1.4.2_08-b03
java.awt.graphicsenv=sun.awt.X11GraphicsEnvironment
java.endorsed.dirs=/usr/lib/jvm/java-1.4.2-sun-1.4.2.08/...
os.arch=i386
java.io.tmpdir=/tmp
line.separator=

java.vm.specification.vendor=Sun Microsystems Inc.
os.name=Linux
sun.java2d.fontpath=
java.library.path=/usr/lib/jvm/java-1.4.2-sun-1.4.2.08/...
java.specification.name=Java Platform API Specification
java.class.version=48.0
java.util.prefs.PreferencesFactory=java.util.prefs.FileSystemPreferences...
os.version=2.4.20-021stab028.19.777-enterprise
user.home=/root
user.timezone=
java.awt.printerjob=sun.print.PSPrinterJob
file.encoding=ANSI_X3.4-1968
java.specification.version=1.4
user.name=root
java.class.path=.
java.vm.specification.version=1.0
sun.arch.data.model=32
java.home=/usr/lib/jvm/java-1.4.2-sun-1.4.2.08/jre
java.specification.vendor=Sun Microsystems Inc.
user.language=en
java.vm.info=mixed mode
java.version=1.4.2_08
java.ext.dirs=/usr/lib/jvm/java-1.4.2-sun-1.4.2.08/...
sun.boot.class.path=/usr/lib/jvm/java-1.4.2-sun-1.4.2.08/...
java.vendor=Sun Microsystems Inc.
file.separator=/
java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport...
sun.cpu.endian=little
sun.io.unicode.encoding=UnicodeLittle
sun.cpu.isalist=
[/code]

Don't mention the 1.4 version..cuz i haven't changed the path yet.
But it worked.

Now what do you think is the problem?
CERTIFIED EXPERT
Top Expert 2016

Commented:
Difficult to say if you only have binary code
CERTIFIED EXPERT
Top Expert 2016

Commented:
If you post test.class somewhere, i may be able to tell you
posting your test.java file would be useful also.
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>posting your test.java file would be useful also.

Does that even exist?
I would hope so.

I mean come on, if you're learning java you should at least have the code form the start.

Author

Commented:
dude..thats a 10mb proj..so dunno if that would be usefull for you?

Author

Commented:
i'm not tryin to learn java..all i need is to run that project and i'm stuck at the java part!
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>dude..thats a 10mb proj.

That's an odd class name for something that size ;-) I'm on dial-up here - so maybe not ;-)
CERTIFIED EXPERT
Top Expert 2016

Commented:
Can you list the directory in which you think your project files reside?
Ok, so what are you doing with the hello world program then ?

Author

Commented:
its a gameserver..

.                       l2jserver.jar
..                      log
LoginServer_loop.sh     log.cfg
RegisterGameServer.bat  mysql-connector-java-3.1.10-bin.jar
RegisterGameServer.sh   servername.xml
banned_ip.cfg           sqljdbc.jar
c3p0-0.9.0.jar          startLoginServer.bat
config                  startLoginServer.sh
console.cfg             startSQLAccountManager.bat
javolution.jar          startSQLAccountManager.sh

Author

Commented:
what am i doing with the hello world is I just wanted to see that my Java is installed correctly.
ok, so did you manage to get the hello world running ?
CERTIFIED EXPERT
Top Expert 2016

Commented:
It is ;-)

sh startLoginServer.sh

(?)

Author

Commented:
actually i need to run this command to start the server

su -c "java -Xms512m -Xmx512m -cp javolution.jar:c3p0-0.9.0.jar:mysql-connector-java-3.1.10-bin.jar:l2jserver.jar net.sf.l2j.loginserver.LoginServer" UserHere

Author

Commented:
Kelvin,
I successfully got the Props.class runnin
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>I successfully got the Props.class runnin

(Hence my last comment)
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>actually i need to run this command to start the server

You should avoid running it as root. Why do you need to?
cool : )

so what error do you get when u start the server now ?

Author

Commented:
i created a superuser..
I had some difficulties on creatin normal user with super permissions
So I had to create a Superuser.

Is that the issue?

Author

Commented:
Exception in thread "main" java.lang.UnsupportedClassVersionError: net/sf/l2j/loginserver/LoginServer (Unsupported major.minor version 49.0)
        at java.lang.ClassLoader.defineClass0(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)

Author

Commented:
I read on the server forums something about this and they say I need to correct the classpath
CERTIFIED EXPERT
Top Expert 2016

Commented:
It means you need to update your JRE. Can you post the output of

java -version
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>Is that the issue?

No, but it shouldn't run as root

Author

Commented:
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Server VM (build 1.5.0_06-b05, mixed mode)

Author

Commented:
seems i'm runnin the latest version.
CERTIFIED EXPERT
Top Expert 2016

Commented:
Hmm, just to be sure, can you post the the output of this?



su -c "java -version"

Author

Commented:
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_08-b03)
Java HotSpot(TM) Client VM (build 1.4.2_08-b03, mixed mode)

You got me!!

I did the export PATH=/path/to/java:${PATH}
which seems to be temporary.

I'm usin two version...cuz i still didn't put the PATH for java on bashrc or where i have to put that because i didn't find anything related to that.

I did the export PATH=/path/to/java:${PATH}
which seems to be temporary.

only a file called bash.bashrc where I can't find anything about the Java path .
CERTIFIED EXPERT
Top Expert 2016

Commented:
You need to run it with the other (later) version
CERTIFIED EXPERT
Top Expert 2016

Commented:
export JAVA_HOME=<insert path to 1.5 install directory>
export PATH=$JAVA_HOME/bin:$PATH

Author

Commented:
ok I did this
but yet if i type su -c"java -version" it shows me i have the older one.
CERTIFIED EXPERT
Top Expert 2016

Commented:
Well as i mentioned, you shouldn't be running as root, but if you must, you need to include the above lines in root's .bashrc

Author

Commented:
OK i tried runnin with a normal user.
Still the same issue
CERTIFIED EXPERT
Top Expert 2016

Commented:
Can you post

su normaluser -c "java -version"

Author

Commented:
java version "1.4.2_08"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_08-b03)
Java HotSpot(TM) Client VM (build 1.4.2_08-b03, mixed mode)

Author

Commented:
can you tell me where exactly do i write the export path so it can be permanent.
that bash.bashrc?

Can i just write that on the first line?
CERTIFIED EXPERT
Top Expert 2016

Commented:
There's your problem. You need to put those export commands in normaluser's .bashrc
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>Can i just write that on the first line?

I'd put it at the end

Author

Commented:
i'm sorry..i'm a newbie at this so can you tell me where do i find the normal users bashrc?
CERTIFIED EXPERT
Top Expert 2016

Commented:
su normaluser
...

<your editor> .bashrc
CERTIFIED EXPERT
Top Expert 2016

Commented:
Domestic matters call. Back later

Author

Commented:
OK i edited that.
Now i don't need to type after every login the export thingy
But on the su user -c "java -version" still keeps tellin me i'm usin the 1.4 version
CERTIFIED EXPERT
Top Expert 2016

Commented:
And you've altered 'user's .bashrc

Author

Commented:
yes..there was only a bash.bashrc file on etc and i altered that one.
I had to change into root account so i can edit the file
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>on etc and i altered that one.

No. The right one's

/usr/home/user/.bashrc

Author

Commented:
I can't find a home folder under usr
CERTIFIED EXPERT
Top Expert 2016

Commented:
su normaluser

<edit command> ~/.bashrc

Author

Commented:
When i created my normal user ..i created from the / directory.
now when i type su user it gets me to the / dir
and there is no .bashrc file
CERTIFIED EXPERT
Top Expert 2016

Commented:
man useradd
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
> yes..there was only a bash.bashrc file on etc and i altered that one.

can you post the change you made

Author

Commented:
sure,
I just added the followin lines on the end of the file

export JAVA_HOME=/path/to/java
export PATH=$JAVA_HOME/bin:$PATH

I tried creatin a normal user on several ways..i read some posts here on exchange but no effect.
I did the following

useradd -d /home/user username
it didn't show me the .bashrc on the home profile

also tried
useradd -d /home/user -s /../crsh username
but when i tried to log in it kept tellin me i type a wrong password.
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
if you've added it to bash.bashrc then you shouldn't need to cheange the users bashrc
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
what does the follwoing return:

/path/to/java/bin/java -version

Author

Commented:
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Server VM (build 1.5.0_06-b05, mixed mode)

Whereever i type java -version i get this.
But when i type su -c "java -version" from anywhere i keep gettin this

java version "1.4.2_08"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_08-b03)
Java HotSpot(TM) Client VM (build 1.4.2_08-b03, mixed mode)


btw, atm i'm having another problem!
I'm startin the server via sh LoginServer_loop.sh but when i go to logs i get an error something like this

Not enough space on Java blah blah

I'll post the exact error later ,my server is down atm so i can't get the error.

Author

Commented:
this is the exact error

Could not reserve enough space for object heap
Could not create the Java virtual machine.
CERTIFIED EXPERT
Top Expert 2016

Commented:
Try

su -m -c "java -version"

Author

Commented:
vs187210:~ # su -m -c "java -version"
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Server VM (build 1.5.0_06-b05, mixed mode)

Author

Commented:
anything?
CERTIFIED EXPERT
Top Expert 2016

Commented:
If you su in that way, you won't have a problem with having the wrong JDK

Author

Commented:
and what exactly means this

"Could not reserve enough space for object heap
Could not create the Java virtual machine."??

I know i'm gettin out of topic scope on every post but the whole topic is about how to bring that server alive.!!
CERTIFIED EXPERT
Top Expert 2016
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
can u post LoginServer_loop.sh

Author

Commented:
thanks a llot for your help  i have some problems with my hosting so i'll close this thread  and give you the points for all your time that you spent helping me (CEHJ)
CERTIFIED EXPERT
Top Expert 2016

Commented:
:-)
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.