aspose file tools*
The moose likes Linux / UNIX and the fly likes Something is wrong with my Java on LInux... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Something is wrong with my Java on LInux..." Watch "Something is wrong with my Java on LInux..." New topic
Author

Something is wrong with my Java on LInux...

Unnsse Khan
Ranch Hand

Joined: Nov 12, 2001
Posts: 511
Hello,
I have been programming with Java for 3 years, and this following question, might sound stupid but I am completely baffled...
I use Linux (Red Hat 9.0)... I was sick of the vim editor and wanted to install gvim so I could use the widgets from gvim...
After installing gvim, I wrote a simple HelloWorld application to test the environment and while javac HelloWorld.java worked, java HelloWorld gave me this error:
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
This is really really astonishing! When I rewrote the program (to say something else other than HelloWorld, for example, HelloMars) in emacs and vi, the same error happened (so I know that its has nothing to do with my "newly installed" version of vim)...
Could this possibly be a virus?
Could I have some corrupted my Java SDK?
Please help!
Here's my CLASSPATH, JAVA_HOME, and PATH settings:
$ echo $JAVA_HOME
/usr/java/j2sdk1.4.2_02
$ echo $CLASSPATH
/usr/java/j2sdk1.4.2_02/lib/tools.jar:/usr/java/j2sdk1.4.2_02/jre/lib/rt.jar:/usr/java/j2sdkee1.3.1/lib/j2ee.jar
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/usr/local/apache-ant-1.5.4/bin:/usr/java/j2sdk1.4.2_02/bin:/usr/java/j2sdkee1.3.1/bin:/usr/local/jboss-3.0.8/bin
when I do a directory listing (in order to see both HelloWorld.java & HelloWorld.class), I get this:
-rw-r--r-- 1 untz untz 425 Nov 13 23:51 HelloWorld.class
-rw-r--r-- 1 untz untz 113 Nov 13 23:51 HelloWorld.java
See, I am baffled because the HelloWorld.class exists in my directory...
I'll even give you guys the basic code to what I tested (again, I am not a beginner, I just encountered this *ANNOYING* problem - that didn't exist, before!).
HelloWorld.java:
============================================================================
public class HelloWorld {
public static void main (String args []) {
System.out.println("Hello World");
}
}
============================================================================
George Brown
Ranch Hand

Joined: Sep 26, 2000
Posts: 919
3 years? Hmm, no, not a virus, or a corrupted SDK, or even anything to do with your editor. Something far more user-related.
Examine your CLASSPATH, which is something that exists on all platforms, Windows, Linux, UNIX, whatever.
Is your HelloWorld.class file in any of the following directories? (these are simply listed from the CLASSPATH that you provided):
/usr/java/j2sdk1.4.2_02/lib/tools.jar
/usr/java/j2sdk1.4.2_02/jre/lib/rt.jar
/usr/java/j2sdkee1.3.1/lib/j2ee.jar
If it is not, you should add another directory to the end of the classpath, that is the directory containing the HelloWorld.class file.
It should then give you the results that you expect.
Hope that helps.
Alton Hernandez
Ranch Hand

Joined: May 30, 2003
Posts: 443
Try doing this:
$ /usr/java/j2sdk1.4.2_02/bin/java HelloWorld
RH9 comes with a package called jdkgcj that supplies a java executable located at /usr/bin. Looking at your PATH, you might be calling this one instead of the one you downloaded from SUN.
[ November 14, 2003: Message edited by: Alton Hernandez ]
Unnsse Khan
Ranch Hand

Joined: Nov 12, 2001
Posts: 511
Thanks for both of your help, but I didn't have include the directory to the classpath, before...
I mean if I go into Dos and am at c:\ and do everything thing I did listed above, the HelloWorld.class does respond to the "java HelloWorld"...
George Brown
Ranch Hand

Joined: Sep 26, 2000
Posts: 919
In your Windows system it sounds like something or someone (probably an SDK installation task) has already set up your environment for java - any DOS shells you spawn would inherit the environment that was already set up in the system.
It's quite possible that your classpath under windows includes a reference to 'C:\' or '.' (the current directory).
Often with linux you have to establish the environment the way you want it.
[ November 14, 2003: Message edited by: George Brown ]
Unnsse Khan
Ranch Hand

Joined: Nov 12, 2001
Posts: 511
Mr. Brown,
Thank you very much for all of your help... For Windoze and Linux, I had the classpath & path system environmental variables set up the same way... My Linux (like a couple of days ago) never encountered this problem and now it does... I was able to compile and run every single piece of interpreted bytecode with the "java" command (that of course had a main method)... Now, it won't recognize it...
This is my theory / what I think really happened...
Remember how I had trouble running the J2EE SDK Reference Implementation on the user "untz"?
Well, I fixed the problem by doing a chmod -R 777 name of the J2EE RI's directory... When I logged into Linux under "untz", the reference implementation worked! (the permissions problem wasn't there, anymore).
I then was noticing how my everytime I ran vim from the command line, that in windoze I could type "gvim" and get a GUI version, whereas, on Linux, it wasn't recognizing the "gvim" executable... I then, finally, downloaded the right version of "vim" that let me run it as gvim from the Linux command line...
Afterwards, I was using apt-get to install synaptic and when I returned to the command line, this was printed 3 times on 3 sequential lines:
$
The world is a crazy place with crazy people.
The world is a crazy place with crazy people.
The world is a crazy place with crazy people.
I figured that someone, somehow, had installed or sent me something stupid via e-mail and that something was in my computer but it wasn't a threat...
So, then I ignored the oddity (the crazy person text which was automatically generated on my shell) and tried out this new version of Linux (just to check if it had syntax coloring, and if it ran the same as the one on my Windoze 2000 Professional system)... Everything seemed to run the same and when I wrote the cheesy Hello World program, the "java" command didn't work...
My theory is that someone gained access into my system via the folder of my J2EE RI (since I did a chmod 777) and sent that message to inform me that he / she had access... And they did something to tamper with it...
What I am going to do, tomorrow, is re-install / re-format my Linux distro and re-install my development environment from scratch (Java SDK, Ant, etc.)
I am very sincere and honest when I say that I was able to run a Java program, something simple, as HelloWorld, in any directory of my Linux distro... Now, for some odd reason, I can't... Usually the classpath is needed for a Java Archive (Jar file) such as servlet.jar, the rt.jar & tools.jar is enough for a HelloWorld program to run... In addition, the gcj compiler is not included in the Red Hat 9.0 distro (which is a great thing)...

Anyone reading this post, please don't do the same mistake as me as use the chmod 777, because hackers will run port scanners and find the entry point into your system...
Now, my problem is going to be alleviated because I will reformat everything but my question to you, is (just like it has been on the other posts) how do I properly enable the J2EE RI to be used as root and also just untz (the usr name I use)?
Tell me what you guys think... The java executable did work like 24 hours ago (before I did the chmod 777) and I did get that stupid message on my shell ("The world is a crazy place ...") a few hours after my I changed the permissions...
Is there anything equivalent to a good open source virus checker that I can install into Red Hat 9.0? How about a firewall like ZoneAlarm?
Thanks for all of your help...
George Brown
Ranch Hand

Joined: Sep 26, 2000
Posts: 919
You should have some firewalling software installed already if you have red hat 9 installed. I believe that the default red hat installation installs firewall by default, advising strongly against no firewall. Read up on iptables, I think there is a tutorial by Oskar Andreasson (sp?) out on the web that would benefit you - search by that name and you should find it.
If you follow the usual principles (strong passwords, never run without a firewall, as few ports open as possible etc) you can minimise the danger, but there is always the possibility that someone could gain access to your machine through a badly-written piece of network software.
As a general rule it's a good idea not to apply world-writable permissions in a recursive manner, you never know when you could have enabled others to change a script that could potentially be run as root (thereby leaving your system wide open).
I'd recommend a good book on unix/linux sysadmin if you want to read up on the subject, ask for recommendations in this forum and I'm sure people will be happy to make suggestions. Read up on users and groups, security.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16058
    
  21

YIPES!
Hold on here!
I run java all the time with a COMPLETELY BLANK classpath!
Well, almost completely blank. You shouldn't have to explicitly include the JDK/JSDK library jars, since they're located by the boot jar loader automagically.
HOWEVER. The "HellowWorld" class is another matter.
Try this:
$ cd myhelloworlddirecory (or wherever)
$ java -classpath . HelloWorld
('$' is your command prompt). The "." is Unix/Linux/DOS for "current directory", just like ".." is "parent directory". This will tell the Java runtime to include the current directory in its search for classes.
Also, just a reminder, if you put a package name on a class, the various levels each map out to a directory. So the class for a file in package "saloon.javaranch" would have to be located in directory ./saloon/javaranch - and upper/lower case is significant.


Customer surveys are for companies who didn't pay proper attention to begin with.
Unnsse Khan
Ranch Hand

Joined: Nov 12, 2001
Posts: 511
Like I said before, my Linux used to work without the classpath for a cheesy program like HelloWorld... You don't have to include the classpath for every single application... It depends on what jars are required...
I used to be able to (like 2 days ago) do this:
$ javac HelloWorld.java
$ java HelloWorld
Hello World!
Now, the second command line invocation (java HelloWorld) doesn't work...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Something is wrong with my Java on LInux...