I have tried running the demo msgsend from JavaMail. I have downloaded version 1.4.5 of JavaMail and unpacked it into my JDK folder. I have added mail.jar to CLASSPATH. I have compiled msgsend.java without getting any error back. However, when I then try running java msgsend I get an "Could not find the main class: msgsend" error.
I am a total noob in Java world and have spend hours browsing through the Internet trying to find an answer but to no avail in my case.
Here is what I get in the console. What am I doing wrong?
C:\Program Files\Java\jdk1.6.0_34\javamail-1.4.5\demo>echo %CLASSPATH%
C:\Program Files\Java\jdk1.6.0_34\javamail-1.4.5\mail.jar
C:\Program Files\Java\jdk1.6.0_34\javamail-1.4.5\demo>javac -cp "%classpath%" ms
gsend.java
C:\Program Files\Java\jdk1.6.0_34\javamail-1.4.5\demo>java msgsend
Exception in thread "main" java.lang.NoClassDefFoundError: msgsend
Caused by: java.lang.ClassNotFoundException: msgsend
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: msgsend. Program will exit.
C:\Program Files\Java\jdk1.6.0_34\javamail-1.4.5\demo>java -cp "%classpath%" msg
send
Exception in thread "main" java.lang.NoClassDefFoundError: msgsend
Caused by: java.lang.ClassNotFoundException: msgsend
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: msgsend. Program will exit.
C:\Program Files\Java\jdk1.6.0_34\javamail-1.4.5\demo>
Classes are case sensitive. Be sure you have the compiled MsgSend in your class path, and invoke the compiled class with the proper case.
Try java MsgSend
Edited:
This is how it will work:
Compile as you were doing:
javac.exe -cp ..\mail.jar msgsend.java
And then to run the compiled class do:
java -cp ..\mail.jar;. msgsend
In other words: you were missing the current folder in your classpath.
You didn't include the directory where msgsend.class exists, usually the current directory ("."). See the examples in README.txt included with JavaMail.
Related
While setting up a JUNIT class for a uni project I keep getting the following error (working in Eclipse Oxygen):
Class not found UnitTest
java.lang.ClassNotFoundException: UnitTest
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:688)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Cant really figure out whats going on, already tried a few question-related answers like clean up the project and checking that the test is running from my project/bin folder.
Hi I am working on weka api in Eclipse Mars. Everything was fine until i wrote a class for LinearRegression, just then Eclipse started giving JNI error. Now other classes runs fine but when i try to run LinearRegression class the error pops up.
The first error is Error: A JNI error has occurred, please check you installation and try again followed by JVM launcher error "A java exception has occurred". And then a list of errors
Exception in thread "main" java.lang.NoClassDefFoundError: no/uib/cipr/matrix/Matrix
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: no.uib.cipr.matrix.Matrix
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
I will appreciate if someone could help me with this problem. Thanks.
I was messing with the JRE setup on Eclipse. Originally the project was set to 1.6 and when set to 1.7, my program started showing a lot of errors. So when i switched back to 1.6, all the compile time errors vanished but i have a new problem now.
This was shown on the console when i tried to run the started class containing the main function. The .class files all exist. Please advice.
java.lang.UnsupportedClassVersionError: Demo : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Exception in thread "main"
Version 51.0 means the are still class files compiled with Java 7. This files wont run with a JRE 6. You have to recompile them first (Rebuild project or clean compile using ant/maven).
Check if java versions match in your Java Build path and Java Compiler in Project properties. I think you compiled with 1.6 and is trying to run with java 1.7
Hi i am getting this error please help me out, thanks
java.lang.NoClassDefFoundError: com/ge/energy/wp/core/exception/WPException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class`enter code here`.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at org.junit.internal.requests.ClassRequest.hasSuiteMethod(ClassRequest.java:62)
at org.junit.internal.requests.ClassRequest.getRunnerClass(ClassRequest.java:50)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:28)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:28)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:24)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:40)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:30)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:445)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.lang.ClassNotFoundException: com.ge.energy.wp.core.exception.WPException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 15 more
try adding source folder to your classpath. If you use eclipse, right click test file and select Run configuration under Junit test and select classpath and add your source folders to class path.
Check class WPException. Usually your IDE should show you if something is wrong with the java file but not with the class file - either it wasn't compiled or missing (the error is triggered when the JVM can't find the class) for some other reason, one of them could be, like bluelabel mentioned, a problem with the PATH.
I know this is old post...but may help someone else...
whenever I have faced this issue only problem have been the java version eclipse is defaulted to - which is the eclipse jre.
Fix - change to the proper jre installed on your machine !
I get the "java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFac
tory" error while running my packaged ejb3 swing client jar. Here's the stack trace.
G:\Courses\OSUMC\Installables\June 5\New>java -jar MetaDB-Client.jar
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interf
aces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: o
rg.jnp.interfaces.NamingContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.<init>(Unknown Source)
at net.massmatrix.metadb.ui.facade.BaseEJBFacade.getInitialContext(BaseE
JBFacade.java:26)
at net.massmatrix.metadb.ui.facade.UserManagerFacade.getUserManager(User
ManagerFacade.java:24)
at net.massmatrix.metadb.ui.facade.UserManagerFacade.isUserNameAvailable
(UserManagerFacade.java:44)
at net.massmatrix.metadb.ui.MainFrame.main(MainFrame.java:269)
Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFac
tory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)
... 8 more
Exception in thread "main" java.lang.NullPointerException
at net.massmatrix.metadb.ui.facade.UserManagerFacade.isUserNameAvailable
(UserManagerFacade.java:44)
at net.massmatrix.metadb.ui.MainFrame.main(MainFrame.java:269)
Here are my packaged swing client Jar contents:-
MetaDB-Client.jar
\net\.. - contains class files(from both client and server)
META-INF
MANIFEST.MF
jndi.properties
Here's my jndi.properties:-
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost:1099
Here's my MANIFEST.MF:-
Manifest-Version: 1.0
Main-Class: net.massmatrix.metadb.ui.MainFrame
Class-Path: jbossall-client.jar
Manifest contents from my jar:-
Manifest-Version: 1.0
Created-By: 1.6.0_18 (Sun Microsystems Inc.)
Main-Class: net.massmatrix.metadb.ui.MainFrame
Command used to create the jar:-
jar cfm MetaDB-Client.jar MANIFEST.MF net\* jndi.properties
Command used to run the jar:-
java -jar MetaDB-Client.jar
I have the jbossall-client.jar in my classpath
G:\Courses\OSUMC\Installables\June 5\New>echo %CLASSPATH%
.;G:\Courses\OSUMC\WORK\Software - New\jboss-5.0.1.GA\client
What else am i missing ?
Thanks.
All you have to do is add the jbossall-client.jar library to the clients lib folder.
ClassPath in the MANIFEST cannot have * in it.
Here is the tutorial for the JAR manifest classpath.