Link to home
Start Free TrialLog in
Avatar of viganothing
viganothing

asked on

Classpath to?

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.
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

try

java -classpath . test
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
>>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.
>>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.
Avatar of viganothing
viganothing

ASKER

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 ?
>>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
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
Do you *have* a jar file? If so, try

java -jar filename.jar
what does your hello world code look like ?
Run the following thus


java -classpath . Props



http://www.sigma-software.freeserve.co.uk/misc/Props.class
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?
Difficult to say if you only have binary code
If you post test.class somewhere, i may be able to tell you
posting your test.java file would be useful also.
>>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.
dude..thats a 10mb proj..so dunno if that would be usefull for you?
i'm not tryin to learn java..all i need is to run that project and i'm stuck at the java part!
>>dude..thats a 10mb proj.

That's an odd class name for something that size ;-) I'm on dial-up here - so maybe not ;-)
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 ?
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
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 ?
It is ;-)

sh startLoginServer.sh

(?)
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
Kelvin,
I successfully got the Props.class runnin
>>I successfully got the Props.class runnin

(Hence my last comment)
>>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 ?
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?
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)
I read on the server forums something about this and they say I need to correct the classpath
It means you need to update your JRE. Can you post the output of

java -version
>>Is that the issue?

No, but it shouldn't run as root
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)
seems i'm runnin the latest version.
Hmm, just to be sure, can you post the the output of this?



su -c "java -version"
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 .
You need to run it with the other (later) version
export JAVA_HOME=<insert path to 1.5 install directory>
export PATH=$JAVA_HOME/bin:$PATH
ok I did this
but yet if i type su -c"java -version" it shows me i have the older one.
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
OK i tried runnin with a normal user.
Still the same issue
Can you post

su normaluser -c "java -version"
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)
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?
There's your problem. You need to put those export commands in normaluser's .bashrc
>>Can i just write that on the first line?

I'd put it at the end

i'm sorry..i'm a newbie at this so can you tell me where do i find the normal users bashrc?
su normaluser
...

<your editor> .bashrc
Domestic matters call. Back later
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
And you've altered 'user's .bashrc
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
>>on etc and i altered that one.

No. The right one's

/usr/home/user/.bashrc
I can't find a home folder under usr
su normaluser

<edit command> ~/.bashrc
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
man useradd
> yes..there was only a bash.bashrc file on etc and i altered that one.

can you post the change you made
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.
if you've added it to bash.bashrc then you shouldn't need to cheange the users bashrc
what does the follwoing return:

/path/to/java/bin/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)

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.
this is the exact error

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

su -m -c "java -version"
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)
anything?
If you su in that way, you won't have a problem with having the wrong JDK
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.!!
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
can u post LoginServer_loop.sh
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)
:-)