I installed eclipse kepler and JDK 1.7.45 on lubuntu 13.04
Here is java version:
nazar@nazar-desktop:~$ java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
nazar@nazar-desktop:~$ echo $JAVA_HOME
/opt/java/jdk1.7.0_45
I configured at eclipse at:
Window => preferences => java => installed jre => add my jdk
I wrote easy test class:
package concurrency;
public class MainTest {
public static void main(String[] args) {
System.out.println("Hello world ");
}
}
But when I run I see error message:
Error: Could not find or load main class concurrency.MainTest
It even doesn't compile this class into src/bin
.
I tried to do it by myself as
javac MainTest.java => java MainTest
It compiles but at run time throws:
Exception in thread "main" java.lang.NoClassDefFoundError: MainTest (wrong name: concurrency/MainTest)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
I couldn't figure out what it can be. Coz installed jdk is compatible with OS system.
UPDATE:
This project was from another machine there was installed java.1.7_40
.
Here I imported this project and keep doing it.
Here is content of eclipse.ini
:
-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20130327-1440.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.200.v20130807-1835
-product
org.eclipse.epp.package.jee.product
--launcher.defaultAction
openFile
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vm
/opt/java/jdk1.7.0_45/bin/java
-vmargs
-Dosgi.requiredJavaVersion=1.6
-XX:MaxPermSize=256m
-Xms40m
-Xmx1024m
-Dorg.eclipse.swt.browser.IEVersion=10001
Any suggestions?
You haven't really made it clear what you've done in Eclipse, but we can easily fix the "compiling and running it from the command line" problem. You're compiling and running it from the wrong directory. Compile it from the root, either like this:
$ javac concurrency/MainTest.java
$ java concurrency.MainTest
or use -d
to specify an output directory:
$ javac -d bin concurrency/MainTest.java
$ java -cp bin concurrency.MainTest
See more on this question at Stackoverflow