cancel
Showing results for 
Search instead for 
Did you mean: 

Executing Java

 
Highlighted
Advisor

Executing Java

Hi, I get following exception:
/opt/java1.5/bin/java /home/user/Hello
Exception in thread "main" java.lang.NoClassDefFoundError: /home/user/Hello


this is my first program:
-------------------------------------------
class Hello {
public static void main (String[] arguments) {
System.out.println("Testing Java...\n");
}
}
-------------------------------------------

I compiled it with:

/opt/java1.5/bin/javac /home/user/Hello.java

There were no compilation errors.

HP-UX 11.11

Is this related to CLASSPATH?
In that case, how to set it properly?

Thanks,

Juan.
5 REPLIES 5
Highlighted
Exalted Contributor

Re: Executing Java

Shalom,

This is pretty simple code.

Are you up to date on OS patches for java and java version from http://www.hp.com/go/java

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Highlighted
Advisor

Re: Executing Java

/opt/java1.5/bin/java -version
java version "1.5.0.11"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0.11-_07_nov_2007_10_59)
Java HotSpot(TM) Server VM (build 1.5.0.11 jinteg:11.07.07-09:52 PA2.0 (aCC_AP), mixed mode)

swlist -l product |grep -i java
Jdk15 1.5.0.11.00 Java 1.5 JDK
Jdk60 1.6.0.00.00 Java 6.0 JDK
Jre13 1.3.1.20.00 Java2 1.3 RTE 1.3
Jre14 1.4.2.17.00 Java2 1.4 RTE
Jre15 1.5.0.11.00 Java 1.5 JRE
Jre60 1.6.0.00.00 Java 6.0 JRE
MyJDBC 5.0.0 MySQL Connector/Java 5.0.0
PHKL_32927 1.0 PA-8800 Fix Java (64-bit JVM) process hang
Highlighted
Honored Contributor

Re: Executing Java

The argument to /opt/java1.5/bin/java is not supposed to be a filename, but a class name.

In other words, "/opt/java1.5/bin/java /home/user/Hello" tries to find from the CLASSPATH directories a .java file that contains a class declaration like:

class /home/user/Hello {
[...]

Of course your program is not written like that: "class Hello" is not the same as "class /home/user/Hello". The latter would be a strange name for the main class of a program.

So, assuming the CLASSPATH has not been set, please try this:

cd /home/user
/opt/java1.5/bin/java Hello

Or, if you want to run your example program from another directory:

cd /
export CLASSPATH=/home/user
/opt/java1.5/bin/java Hello

MK
MK
Highlighted
Advisor

Re: Executing Java

Hi Matti,

I performed:

$ cd /home/user
$ /opt/java1.5/bin/java Hello
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
$
Highlighted
Advisor

Re: Executing Java

more hello.java
import java.util.*;
class hello {
public static void main(String args[]) {
System.out.print("Hola\n");
}
}

/opt/java1.5/bin/javac hello.java
/opt/java1.5/bin/javah -jni hello

That WORKED.

THANKS.

JUAN.