Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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 java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    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)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
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.....

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

2 Answers 2

From this link:

3 ways to resolve NoClassDefFoundError in Java

1 Class is not available in Java Classpath ( How to Set Classpath for Java on Windows Unix and Linux ).
2 You might be running your program using jar command and class was not defined in manifest file's ClassPath attribute.
3 Any startup script is overriding Classpath environment variable.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.