when running the jar in command line, throw this exception:
java.lang.ClassNotFoundException
When building jar in intellij, we need set the manifest properties, like main class, class path, where could I find the right setting for this? it is not in the manifest file
Related
I still encounter this error even if I included the svnant-1.3 jar in this path of my Eclipse plugin C:\Development\Java\eclipse\plugins
\org.apache.ant_1.8.4.v201303080030\lib\svnant-1.3.jar
taskdef A class needed by class org.tigris.subversion.svnant.SvnTask cannot be found: org/tigris/
subversion/svnclientadapter/SVNClientException using the classloader AntClassLoade
What else can be done for this? I checked svnant jar ant SvnTask class is there
I have a jar file exported from Eclipse (Runnable JAR>>Copy required libraries into a sub folder).
In java if you set the main class in the manifest.xml you can run:
java -jar MyTest.jar arguments
if you want to run another main class in the jar file or if you didn't set a main class in the manifest.xml you can run:
java -cp MyTest.jar MyOtherMainClass arguments
In Hadoop if main class is set in manifest.xml you can run:
hadoop jar MyTest.jar arguments
If you type:
hadoop jar MyTest.jar MyOtherMainClass arguments
It will consider MyOtherMainClass as argument (not as a class to run) in the "args" array of the original main class of jar.
Now if you want to run another main class in the jar file what will you type?
I expect something similar to:
hadoop java -cp MyTest.jar MyOtherMainClass arguments
but that gives:
Error: Could not find or load main class java
Notice: if I remove "hadoop" from "hadoop java -cp MyTest.jar MyOtherMainClass arguments" it will launch normally
The problem comes from Eclipse forcing you to set the main class in the jar file and hence preventing you to run the class that you want. All you have to do is remove the main class from the manifest.xml file of the jar file and run:
hadoop jar MyTest.jar MyOtherMainClass arguments
Take a look here:
http://www.roman10.net/2012/07/26/specify-the-main-class-in-a-jar-file-for-hadoop/
I typed the same text in case the url deleted:
Hadoop support execution of jar file. For an executable jar file in normal java execution, one can specify the main class in the command line, as covered in my previous post: switch between main classes in a jar file.
However, the rules are a bit different for executable jar file running with hadoop. Basically the following rules hold (I tested on Hadoop 1.0.3),
If a jar file contains a main class specified in its manifest file, hadoop will take the main class even if the command specify another main class. This is different from normal java execution where we can specify a main class to overwrite the one in the manifest file.
If a jar file does not contain a main class in manifest file, hadoop allows us to specify the main class.
At eclipse, when one export a project as runnable jar file, it always ask for a main class at Launch configuration.
The main class selected will be put in the manifest file. Below is the content of the META-INF/MANIFEST.MF file in my helloworld project where the main class is set to HelloWorld.
Manifest-Version: 1.0
Class-Path: .
Main-Class: hello.HelloWorld
One can browse the jar file using a file extractor, open the manifest file using a file editor, and simply delete the last line to remove the main class configuration, and save the changes to the jar file when prompted. This will create a runnable jar file without main class.
The modified jar file can then be used in Hadoop with user supplied main class configuration, as shown in the sample command below,
$ hadoop jar hello.jar hello.HelloWorld
I wrote maven project and it run correctly in Eclipse but I want to run maven project in cmd line so I write this line in cmd
java -cp target/my-app-1.0-SNAPSHOT.jar com.my.App
I have this error
Could not find or load main class com.my.App
How I solved it?
I have an Eclipse Mars project compiling to a jar file with a Spring bean definition file in the following path: my-project.jar/spring/config.xml
This artifact is included in another Eclipse webapp project (via Maven). When I expand the contents of the compiled war file, I can see that the my-project.jar file and its contents (i.e. config.xml) exist.
Inside the webapp, I have a Spring definition file (WEB-INF/classes/spring/context.xml) and it has an import statement for config.xml as follows: <import resource="classpath:spring/config.xml"/>
I run into issues, when I launch the webapp (via Eclipse). I get the following exception:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [data.xml]
Offending resource: class path resource [spring/context.xml]; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:spring/config.xml]
The file is in the classpath, so I assume there is some class loader issue that I can't figure out. Strangely, this issue is inconsistent. There was once or twice that starting up the webapp produced no errors.
Put a slash in front when your bean definition XML file is in some folder:
<import resource="classpath:/spring/config.xml"/>
I exported my Eclipse project as a runnable Jar file, added a manifest, as well as the appropriate class files with the command:
jar cfm JarFile.jar manifest.txt *.class
However, when I try to run the jar file with
java -jar JarFile.jar
I get the error that it "Could not find or load main class" etc. etc.
The structure of my manifest.txt file looks like this:
Main-Class: EclipseProjectName.src.packagename.mainclassname
(With a carriage return at the end)
Is something wrong with my manifest file? If not, what may be the reason that the main class cannot be found?
Thank you!
The manifest file extension should be .mf i.e manifest.mf. See here for jar file specification
Suggest to use fat jar eclipse plugin for exporting java projects as runnable jars.
Edit
Correct the content of manifest.txt as shown below
Main-Class: EclipseProjectName.src.packagename.mainclassname
project name and src are not required. Refer this
The entry in the META-INF/MANIFEST.MF entry in the finished jar file should be
Main-Class: packagename.mainclassname
and should correspond exactly to
/packagename/mainclassname.class
in your jar file (or jar file_s_ if you use Class-Path too).