# Why does running bash scripts containing Java commands give me “missing classes” error?

A have few .sh files that I want to run.

I was a regular Windows user, so i haven't much of idea about it. I had .bat files, which were doing proper work for me. But when I switched to Ubuntu it's showing an error:

proton@proton-5750:~/Desktop/nand to tetris$./HardwareSimulator.sh Exception in thread "main" java.lang.NoClassDefFoundError: HardwareSimulatorMain Caused by: java.lang.ClassNotFoundException: HardwareSimulatorMain at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) at java.lang.ClassLoader.loadClass(ClassLoader.java:266) Could not find the main class: HardwareSimulatorMain. Program will exit. proton@proton-5750:~/Desktop/nand to tetris$ ./HardwareSimulator.sh
Exception in thread "main" java.lang.NoClassDefFoundError: HardwareSimulatorMain
Caused by: java.lang.ClassNotFoundException: HardwareSimulatorMain
at java.net.URLClassLoader$1.run(URLClassLoader.java:217) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at java.lang.ClassLoader.loadClass(ClassLoader.java:321) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
Could not find the main class: HardwareSimulatorMain. Program will exit.


I don't why these Java errors are happening in Ubuntu...

Guys give me solution, thanks in advance.....

-
i've tried sh filename.sh and bash filename.sh, still the problem n error is same.... –  sumit Jul 8 '12 at 17:17
The problem is not the sh file, but that it includes Java commands. –  izx Jul 8 '12 at 18:50

The most likely thing is that the shell script (for starting a Java program) has been ported from Windows but the construction of the classpath is still using semicolons ; on Linux, the PATH separator is the colon. Try replacing semicolons in the -cp parameter with colons. Or alternately, since the default Java install in Ubuntu is Java 6, the wildcard form for the -cp parameter will work - pass the folder containing the jar files, with a /* at the end. You'll have to enclose that in single quotes so that the shell doesn't expand it.

-