java.lang.ClassNotFoundException with IntelliJ - java

I've been searching for a solution that works but none have so far. When I try to run a program that is known to work for others, I get this error:
"C:\Program Files\Java\jdk1.7.0_65\bin\java" -Didea.launcher.port=7534 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 14.0.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.7.0_65\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.7.0_65\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.7.0_65\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.7.0_65\jre\lib\jce.jar;C:\Program Files\Java\jdk1.7.0_65\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.7.0_65\jre\lib\jfxrt.jar;C:\Program Files\Java\jdk1.7.0_65\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.7.0_65\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.7.0_65\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.7.0_65\jre\lib\resources.jar;C:\Program Files\Java\jdk1.7.0_65\jre\lib\rt.jar;C:\Program Files\Java\jdk1.7.0_65\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.7.0_65\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.7.0_65\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.7.0_65\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.7.0_65\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.7.0_65\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.7.0_65\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.7.0_65\jre\lib\ext\zipfs.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 14.0.3\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain gui.WFPaLM
Exception in thread "main" java.lang.ClassNotFoundException: gui.WFPaLM
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
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 java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:116)
Process finished with exit code 1
The directory "src", which contains all of the packages, is set as the Source Folder.
Edit: http://imgur.com/O45zm4t,MPYuDCa that is what my project structure looks like.
Edit 2: I downloaded the community edition of intellij, and it worked. It's a mystery as to why.

Have you compiled the project before running? (Build > Make Project Ctrl+F9). Normally IntelliJ IDEA compiles a project automatically before running, but perhaps you have disabled this.

Related

Exception in thread "main" java.lang.NoClassDefFoundError: java/util/function/Predicate

I have created a jar file using
mvn assembly:assembly -DdescriptorId=jar-with-dependencies
and I run it on windows and it works fine and works as expected. Then I run it on Ubuntu and it gives the following exception:
Exception in thread "main" java.lang.NoClassDefFoundError: java/util/function/Predicate
at Maxima_ImageJ.run(Maxima_ImageJ.java:13)
at Maxima_ImageJ.main(Maxima_ImageJ.java:27)
Caused by: java.lang.ClassNotFoundException: java.util.function.Predicate
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
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)
... 2 more
I have no idea why it works differently in Windows and Ubuntu. If someone do, please help. Is it related to the versions of java?
Set class path to Java 1.8 as java.util.function.Predicate is part of JavaSE8 and will not be available in 1.7 some of the set commands to use before executing maven command.
set path=C:\Program Files\Java\jdk1.8.0_05\bin//UPTO Bin
set JRE_HOME=C:\Program Files\Java\jre8//Upto Root folder of JRE
set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_05//UPTO Root folder of JDK
Check your java version by using below command.
readlink -f $(which java)
If it is less than 1.8, then you have to update Java_Version.
One way is to edit in .bashrc file.

Running a java program via nailgun

Can someone please explain how do I start a program called main.java using Nailgun. It's been a complete nightmare for me and I cannot find any sort of tutorial on the web which explains it clearly.
Do I need to include anything extra in my program to run them?
I'm trying to follow the instructions given on the Nailgun website where it says:
Launch the Nailgun server with "java com.martiansoftware.nailgun.NGServer"
But the output I get is:
Error: Could not find or load main class com.martiansoftware.nailgun.NGServer
Also, when I try to run my compiled java program, the output is:
java.lang.ClassNotFoundException: main
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
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 java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:274)
at com.martiansoftware.nailgun.NGSession.run(NGSession.java:261)
I think the idea with nailgun is that you have to include the classpath when you launch the server, like this:
$ java -cp /usr/share/java/nailgun-0.9.0.jar:path/to/myapp.jar -server com.martiansoftware.nailgun.NGServer 127.0.0.1 &
NGServer started on 127.0.0.1, port 2113.
[1] 22443
$ ng-nailgun com.user4215685.main

Java program executes in eclipse but not in terminal

I am using Eclipse with Eclipse Maven Plugin (m2e).
My java program compiles and run correctly from eclipse interface but I am unable to compile and run it from terminal.
My Eclipse Setting:
I am using two third party APIs, for which in eclipse build path I added
"/home/syed/workspace/FirstMaven/target/resources/fuse-jna-master/build/classes" (as external class folder)
"/home/syed/workspace/FirstMaven/target/resources/apache-jena-2.11.1/lib" (as external jars)
Package:
package org.organization.upesh.FirstMaven;
My Project path:
syed#ubuntu:~/workspace/FirstMaven$
Source Code Directory Path:
syed#ubuntu:~/workspace/FirstMaven/src/main/java/org/organization/upesh/FirstMaven$
Classes Directory:
syed#ubuntu:~/workspace/FirstMaven/target/classes/org/organization/upesh/FirstMaven$
When I try to execute myProgram via below command
syed#ubuntu:~/workspace/FirstMaven/target/classes$ java org.organization.upesh.FirstMaven.myProgram
it gives me these errors:
Exception in thread "main" java.lang.NoClassDefFoundError: net/fusejna/util/FuseFilesystemAdapterFull
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)
Caused by: java.lang.ClassNotFoundException: net.fusejna.util.FuseFilesystemAdapterFull
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
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)
... 13 more
But my test program that do not use the third party API runs correctly via:
syed#ubuntu:~/workspace/FirstMaven/target/classes$ java org.organization.upesh.FirstMaven.test
I think myProgram is not executing because of the two APIs (class folder and jar folder) that I am using.
I have added path of class and jar folders of the APIs to /etc/environment (given below) and rested my computer, but still the same error
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/syed/workspace/FirstMaven/target/resources/apache-jena-2.11.1/lib:/home/syed/workspace/FirstMaven/target/resources/fuse-jna-master/build/classes"
Please guide me how to run my program correctly
JVM does not get libraries from PATH. It uses special environment variable CLASSPATH that can contain a list of directories or jar files separated by colon on Unix or semicolon on Windows.
So, just define CLASSPATH and put references to all your libraries there.
Aleternatively (and IMHO better) use command line switch -classpath (or its alias -cp) when running java:
java -cp mylib1.jar:mylib2.jar com.mycompany.Main

ClassNotFoundException on simple Hello World in IntelliJ

I am using IntelliJ, and get a ClassNotFoundException, even when doing a simple Hello World program. After googling and looking at how to add directory to classpath in an application run profile in intellij idea?, I tried changing my dependencies to the JDK folder (/Library/Java/JavaVirtualMachines/jdk1.7.0_10.jdk), and to no avail.
I have also tried re-installing the JDK and re-installing IntelliJ, both to no avail, and I can run programs in NetBeans without issue. What's going on? Is this some strange bug with IntelliJ?
Code:
public class AppMain {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
Error:
/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/bin/java -Didea.launcher.port=7532 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA 13 CE.app/bin" -Dfile.encoding=UTF-8 -classpath "/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/lib/javafx-doclet.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/lib/tools.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/htmlconverter.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/JObjC.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_10.jdk:/Applications/IntelliJ IDEA 13 CE.app/lib/idea_rt.jar" com.intellij.rt.execution.application.AppMain AppMain
Exception in thread "main" java.lang.ClassNotFoundException: AppMain
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
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:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:188)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:113)
Process finished with exit code 1
I've found out what sorted it. It was a bug with my import settings, deleting my preferences (i.e. going to ~/Library/Preferences and doing rm -r IdeaIC13) sorted this issue out. Hopefully that's helpful to anyone else coming across this issue.

Run DiscardServer of Netty 4.0 from downloaded source directory

I am trying to run the DiscardServer module of a Maven compiled program called Netty, which I have downloaded as source code. I'm using a GNU/Linux command line terminal to try and follow the instructions in the manual http://netty.io/wiki/user-guide-for-4.x.html.
I'm assuming I should run DiscardServer in directory example/src/main/java, but when I move to that directory and type
$ java -cp "~/norbert/netty-master/all/target/netty-all-5.0.0.Alpha1-SNAPSHOT.jar:~/norbert/netty-master/all/target/netty-all-5.0.0.Alpha1-SNAPSHOT-sources.jar" io.netty.example.discard.DiscardServer
the response is "Error: Could not find or load main class io.netty.example.discard.DiscardServer"
I know the class can be run from a source directory somehow, because
$ java io.netty.example.discard.DiscardServer
produces
Exception in thread "main" java.lang.NoClassDefFoundError: io/netty/channel/EventLoopGroup
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
at java.lang.Class.getMethod0(Class.java:2685)
at java.lang.Class.getMethod(Class.java:1620)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:492)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:484)
Caused by: java.lang.ClassNotFoundException: io.netty.channel.EventLoopGroup
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
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:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 6 more
Having downloaded the binary version netty-4.0.13.Final in addition, I was able to start the discard server in directory netty-4.0.13.Final/jar as follows:
$ java -cp "netty-example-4.0.13.Final.jar:netty-transport-4.0.13.Final.jar:netty-common-4.0.13.Final.jar:netty-buffer-4.0.13.Final.jar" io.netty.example.discard.DiscardServer
How can I run the DiscardServer from directory example/src/main/java or the relevant source directory, though? Thanks, any help would be appreciated.
inside the example folder, you should run:
mvn install
then
mvn exec:java -Dexec.mainClass="io.netty.example.discard.DiscardServer"

Categories

Resources