I am using javax.mail .jar file to read the mail messages. But when i m running the code i am getting the following exception.
I added mail.jar in classpath.
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingE
xception
Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException
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: MasterProcess. Program will exit.
any suggetionsn to solve this issue please ...
You're not getting a MessagingException, the VM is complaining that it can't find MessagingException (although it's probably that it's looking for it because it wants to throw it, but those are issues for later).
Check if your mail.jar actually contains this class, and check if your mail.jar really is on the classpath.
The last thing that could happen is that the class is incompatible with your version of Java. Classes compiled for 1.5 won't run on 1.4, for example.
Working in eclipse and not in command line clearly say that there is multiple versions of mail jar present in the project.
Ex:
You have 3 Jars , Jar X, Jar Y and Jar Z.
With out you knowing JAR X might be already be bundled inside JAR Z ( in this case mail jar but some different version.
So what is the problem in having multiple version of same jar ?
You have two different versions and you will not know which will be referenced in your project. (so if you are looking for some class from mail-2.jar in your project you will get class not found exception if the reference is made to mail-1.jar by class loader)
So how come its working properly on Eclipse ?
In eclipse you can see there is an option for ORDER the library, these will be reference in the same order, but while running in command prompt we used to load the as lib/* which loads all to gather and we will not know which lib will get loaded first.
How to identify the culprit and fix the issue ?
Option 1 :
See docs page / user guide of the libs you are using to see what they have in them.
Option 2 :
In eclipse move the JAR in question (mail.jar here) to TOP in the class path order. (your program should work now)
Now bring down the order one by one to see where you get the error. (if you wish to find the jar which is causing this issue , duplicate reference)
Extract the jar which has the duplicate reference remove the duplicate inside the JAR and repackage it. (if required)
Also be sure you're having also the java activation.jar jar.
Are you by any chance working with an App Server (eg. Jboss), if so, just check classloading model (in jboss with single classloading model you may be loading a not so up-to-date version of the jars)
I've also faced the same error. It happens to me that while compiling i used the jars correctly. While running it on command line i noticed the mail.jar (javamail API) was not included.
Related
I'm trying to use neo4j embedded in a Java application for a small project of mine. For this, I'm only using JDK Tools, so, there's no Eclipse, Net Beans or IntelliJ IDEA.
I've tried to follow the tutorial supplied by Neo4j (Include Neo4j in your project) , but I'm somehow doing it wrong, since it doesn't work.
To sum up, I've got a small .java file, let's say it's only composed of the bare necessities to work and an import of org.neo4j
import org.neo4j; // or org.neo4j.*, or anything else that starts with that
public class Application
{
// only the bare necessities to work
}
I'm trying to compile this simple code with javac using -classpath to specify where to find Neo4j libraries, just like it's showed in the tutorial
javac -g -cp "C:/Path/to/libs/Neo4j Community/jre/lib" Application.java
But each time, the compilation fail at the line of the import, saying that the package doesn't exist. And of course, once this line is erased, the compilation succeed.
I've already tried to move the libs inside the project's folder, and I've tried to download the neo4j kernel jar and put it inside the Neo4j's folder and the project's folder, but, none of these solutions have worked.
If anyone could help me, I would be very thankful to him.
Cordially,
Jaxon
EDIT : When I try to compile with the following command :
javac -g -cp "C:\Path\to\libs\Neo4j Community\jre\lib\*" Application.java
The error stays and two warnings appear. I don't know if it's related, but here are the errors :
warning: Supported source version 'RELEASE_7' from annotation processor 'org.neo4j.kernel.impl.annotations.ServiceProcessor' less than -source '1.8'
warning: Supported source version 'RELEASE_7' from annotation processor 'org.neo4j.kernel.impl.annotations.DocumentationProcessor' less than -source '1.8'
Application.java:4: error: package org.neo4j does not exist
import org.neo4j.*;
^
1 error
2 warnings
EDIT : I now have a program that compiles, but when I run it, there is an exception that crash the program. The code haven't changed a lot, the only difference is that now I import org.neo4j.graphdb.* and org.neo4j.graphdb.factory.*
Here is the exception returned :
Exception in thread "main" java.lang.NoClassDefFoundError: org/neo4j/graphdb/factory/GraphDatabaseFactory
at MyApp.connection(MyApp.java:18)
at MyApp.<init>(MyApp.java:13)
at MyApp.main(MyApp.java:8)
Caused by: java.lang.ClassNotFoundException: org.neo4j.graphdb.factory.GraphDatabaseFactory
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)
... 3 more
Well I understand what the exception means but I don't know how to solve the problem. Probably because according to the Neo4j documentation, GraphDatabaseFactory is in org.neo4j.graphdb.factory. So I don't know where to go...
You need to use a * wildcard to specify all the jar files in the lib folder. Try this:
javac -g -cp "C:/Path/to/libs/Neo4j Community/jre/lib/*" Application.java
[EDIT]
Of course, you must use your computer's actual path to the lib directory. "C:/Path/to/libs/Neo4j Community/jre/lib/*" is just an example.
Also, warnings like the following (which mean that some parts of the library were annotated to indicate that they support Java 1.7, but you are compiling with Java 1.8) may not prevent the resulting .class files from running properly:
warning: Supported source version 'RELEASE_7' from annotation processor 'org.neo4j.kernel.impl.annotations.ServiceProcessor' less than -source '1.8'
However, if you want to be sure, one way to get rid of this warning is to downgrade your JDK to 1.7.
(I just asked this in the Gradle forum, but I concluded that SO just works better.)
I'm looking at modifying an existing Gradle build script. It currently tries to execute "ant" in order to run a target from a specific Ant build script. This appears to be platform-specific, and it fails on my Windows box. I'm attempting to convert it to the more portable (?) process of importing the build script and executing the desired converted task.
The first thing I did was just add the "ant.importBuild" statement just before the existing target, and ran that. This fails with the following root cause:
Caused by: java.lang.ClassCastException: org.apache.xerces.parsers.XIncludeAwareParserConfiguration cannot be cast to org.apache.xerces.xni.parser.XMLParserConfiguration
at org.apache.xerces.parsers.SAXParser.<init>(Unknown Source)
at org.apache.xerces.parsers.SAXParser.<init>(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.<init>(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl.<init>(Unknown Source)
at org.apache.xerces.jaxp.SAXParserFactoryImpl.newSAXParser(Unknown Source)
at org.apache.tools.ant.util.JAXPUtils.newSAXParser(JAXPUtils.java:215)
at org.apache.tools.ant.util.JAXPUtils.getNamespaceXMLReader(JAXPUtils.java:172)
at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:244)
at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:177)
at org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java:93)
at org.apache.tools.ant.ProjectHelper$configureProject.call(Unknown Source)
at org.gradle.api.internal.project.DefaultAntBuilder.importBuild(DefaultAntBuilder.groovy:76)
From the related occurrences of this on the web, it's clear there's a classpath conflict (that didn't tell me anything that wasn't obvious), but I don't know how to resolve this.
The build scripts in question are from the Mockito code base (https://github.com/mockito/mockito), so you can see them there. I only added "ant.importBuild 'build-ant.xml'" just before the place where the Ant target is executed.
I got similar problem with xerces before which caused by a newer version xerces was used automatically due to gradle use newer one by default.
I will suggest you use gradle's dependencies task to check
I'm trying to run ParSeMiS. According to the documentation, it requires ant, prefuse and antlr jars to be available in its lib directory. I've put all the required jars in it. However, when I try to run it, I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: antlr/TokenStreamException
at de.parsemis.miner.environment.Settings.parseFileName(Settings.java:198)
at de.parsemis.miner.environment.Settings.parseOption(Settings.java:312)
at de.parsemis.miner.environment.Settings.parse(Settings.java:170)
at de.parsemis.miner.environment.Settings.parse(Settings.java:122)
at de.parsemis.Miner.run(Miner.java:358)
at de.parsemis.Miner.main(Miner.java:61)
Caused by: java.lang.ClassNotFoundException: antlr.TokenStreamException
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 6 more
Now, I've verified that antlr/TokenStreamException.class is present in the antlr jar. I have tried adding the jar manually to the classpath by both exporting the CLASSPATH variable and setting it via the -cp switch. However, none of that works, and I still get this exception. Can anybody help me figure out what's wrong? Thanks.
The problem is that you're using -jar which ignores your CLASSPATH environment variable. You should list your dependencies in the manifest, as shown here, e.g.
Class-Path: lib/ant.jar lib/antlr-3.4-complete.jar lib/prefuse.jar
(It should have still worked with an explicit -cp option, however. My guess is that you got something wrong when specifying that, and assumed it was the same underlying cause as the failure when using the environment variable.)
I realize this question is very old, but I just had exactly the same problem and found this thread. For posterity, I'm posting how I did eventually get it to run:
As mentioned above, when running with -jar, java apparently ignores the class path. So don't run it with -jar. instead include the jars in the path and run the class directly. Poking around, the following should work (paths are on my Ubuntu 12.10 system):
java -cp /usr/share/java/antlr.jar:/full/path/to/parsemis.jar de.parsemis.Miner
You can then pass in options to the above. Maye sure you use full paths, and no shortcuts like ~/foo, as they apparently don't expand.
Of course, if you're using a Dot-formatted graph like I am, it dies very early on complaining of "unexpected char 0xA", but at least it gets further.
I have a mavenized, multi-module spring-based(3.0.1) application that runs in tomcat. I'm trying to create a standalone tool that I can distribute to users via a single jar(so they can just double-click on it), that bundles in some of the modules of the application mentioned above.
I've used the maven-shade-plugin to assemble this jar. If I explode the jar it appears as if all of the dependencies are there and the two spring metadata files have been properly concatenated from all of the individual spring jars. The application runs, up until the point where I attempt to instantiate a ClassPathXmlApplicationContext. When a user clicks a button in the application, the following method is executed:
public void createAppContext() {
ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext(springFiles);
}
"springFiles" is declared in the class as follows:
public final String[] springFiles = { "/applicationContext-beans.xml" };
When the above method is executed the following error appears:
Exception in thread "Thread-8" java.lang.ArrayIndexOutOfBoundsException: 3350
at org.springframework.asm.ClassReader.(Unknown Source)
at org.springframework.asm.ClassReader.(Unknown Source)
at org.springframework.asm.ClassReader.(Unknown Source)
at org.springframework.core.type.classreading.SimpleMetadataReader.(SimpleMetadataReader.java:48)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)
at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:82)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:76)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.checkConfigurationClassCandidate(ConfigurationClassBeanDefinitionReader.java:302)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:157)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:132)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:584)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:405)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:93)
at com.mycompany.StandaloneTool$2.run(StandaloneTool.java:124)
Any help would be greatly appreciated!
Just a hunch but it may be the shade plugin overwriting the metadata that Spring uses for it's namespaces in the configuration file. Have a look at merging content of specific files in the documentation for the shade plugin to see if it solves your problem.
The spring meta-data files appeared to be copied correctly. I started using the maven-shade-plugin for this specific reason. :)
I upped the spring logging to TRACE, which revealed some more information(I should have done this to start, oops!). I was getting a bunch of exceptions saying that various .class files had invalid java magic numbers.
It turns out that the issue was in how I was using the maven-dependency-plugin. My intent was to pull in a .zip artifact, unpack it, and copy it's contents to a specific build directory during the generated-resources phase. One potential problem is that I had inadvertently used the goal "unpack-dependencies" which pulled in more dependencies than I had intended(dependencies that ultimately the maven-shade-plugin would bundle in anyway). However, what seemed to finally resolve the issue was the removal of the artifact item property "output-directory" where I specified a directory called "generated-resources". Once I removed this property, everything ran smoothly.
It's not clear to me why the magic numbers on the .class files were being changed/corrupted, but at least the problem has been resolved. Anyone have any ideas as to what actually happened?
Thanks for all the input!
I'm developing a eclipse plugin rcp and I'm running into a NoClassDefFoundError
Exception in thread "Thread-7" java.lang.NoClassDefFoundError: org/jdom/input/SAXBuilder
at org.geonames.WebService.search(WebService.java:783)
at geo.GeocoderGeonames$SearchThread.run(GeocoderGeonames.java:119)
Caused by: java.lang.ClassNotFoundException: org.jdom.input.SAXBuilder
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:483)
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:399)
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:387)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:87)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 2 more
The class that supposedly cannot be found is in a jar that I have added to the buildpath. I don't get any compile error etc only this exception when the running application enters the code where this class is needed...
Is there some other place I need to add the jar
After reading this added the jar to the MANIFEST.MF, which solved the problem.
As I understand it, eclipse starts several classloaders which only sees what MANIFEST.MF tells them to see and ingnores the build path...
How are you running your plug-in? You may need to add the JAR to the class path in the VM arguments.
In our experience a NoClassDefFoundError can sometimes mean that more than one version of a Class are found, as there is also a ClassNotFoundException that's normally thrown if a class cannot be found.
Another reason in your case (XML parser) might be something with endorsed classes. Are you directly importing the jdom classes or something like org.w3c...? If so, have a look at the "endorsed classes" system of Java, something that I just recently came across.