Reputation: 1771
I have following directory structure and files:
Folder
+
|--/org
|--Online.java
|--Online.class
When I execute following code:
C:\>cd Folder
C:\Folder>java Online http://www.google.com google.html
My files execute and give me correct output as per my requirement.
Now, I want to add the package 'org' and Online.class file in one Jar file say E.g. Online.jar
I did that by executing following code:
jar cvf Online.jar *
Now, when i am trying to execute following code:
java -jar Online.jar http://www.google.com google.html
It's shows me error:
Failed to load Main-Class manifest attribute from Online.jar
Can any one help me out here? I want to know What is wrong here ?
Upvotes: 2
Views: 219
Reputation: 2672
I normally use the command jar -cmf MANIFEST_FILE jarfile.jar *.class
and specify a custom Manifest file as I get the same errors as you do.
This is the simple Manifest File I use, (src)
Manifest-Version: 1.0
Class-Path: .
Main-Class: MainClassName
Warning: The manifest must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.
When running, I use java -jar jarfile.jar
or just double click the .jar on Windows.
Upvotes: 0
Reputation: 7925
Assuming your FQCN is org.Online (which is a bit awkward) the structure should be:
Folder
+
|--org
| +
| |--Online.class
|
|--META-INF
+
|--MANIFEST.MF
That is:
The contents of META-INF/MANIFEST.MF should be:
Manifest-Version: 1.0
Main-Class: org.Online
That is, specify the fully-qualified class name.
Upvotes: 1
Reputation: 749
It depends on how you build your jar. You will need a Manifest file with the main class name
I usually use a ant to build, so my build task looks like this:
<target name="Build_myjar">
<jar destfile="my.jar" filesetmanifest="mergewithoutmain">
<manifest>
<attribute name="Main-Class" value="MyMainClass"/>
<attribute name="Class-Path" value="."/>
</manifest>
<fileset dir="bin"/>
</jar>
</target>
Notice the Manifest already has the MainClass Name, hence that takes care of invoking the MainClass
Upvotes: 2
Reputation: 1294
I think the default manifest may need to be modified to include the main-class...
Main-Class: Online.class
Upvotes: 1