I am trying to creat JAR file through eclipse. I read some of the threads from
stackoverflow as well as other forums. But nothing is helping.
I have created a separate manifest file like this one.
Manifest-Version: 1.0
Main-Class: Main
Class-Path: gnujaxp.jar iText-2.1.5.jar jcalendar.jar jcommon-1.0.16.jar jfreechart-1.0.13.jar jfreechart-1.0.13-experimental.jar jfreechart-1.0.13-swt.jar junit.jar servlet.jar swtgraphics2d.jar tinyos.jar
I have put all this jars in same project folder.
While exporting i am exporting all resources (meants this jar files also.)
But still i am getting noclassdeffound error when my application tries to load any one of the jar included.
M i wrong anywhere ..
Thanks in advance.
If you are using eclipse >=3.4 try "export as runnable jar file" it should generate it correctly.
Otherwhise you can provide your own manifest file in the export as jar dialog.
I get this error and find that my manifest needs a space after the jars in the class-path. This includes the ones at the end of the line and end of list, otherwise it mashes them together.
Be sure to add an empty line at the end of your Manifest file.
Related
I have some dependencies that I need to specify in the manifest. So I created a manifest file manually and when doing that I exported my selected files and do next >> next and then choose "use existing manifest from file". this is the manifest I have locally:
Manifest-Version: 1.0
Main-Class: com.placeholder.ProcessServer
Class-Path: . ProcessServer_lib/commons-net-3.3.jar ProcessServer_lib/
com.ibm.mq.headers.jar ProcessServer_lib/db2jcc.jar ProcessServer_lib
/db2jcc_license_cu.jar ProcessServer_lib/db2jcc_license_cisuz.jar Pro
cessServer_lib/com.ibm.mq.jar ProcessServer_lib/com.ibm.mq.commonserv
ices.jar ProcessServer_lib/connector.jar ProcessServer_lib/com.ibm.mq
.jmqi.jar ProcessServer_lib/log4j-1.2.17.jar
I placed the jar in my unix box and invoke it via a shell script using -jar however it gives me a classdef not found exception. Upon seeing the jar generated via decomplier/zip utility I can see the manifest only contains the main-Class line not the class-path.
While exporting the jar should I unselect the buildpath that comes in the right hand box selection ?
I'm doing these deployment works for the first time, but I have tried for 1 day using -cp to specify jar folder and main class but I still haven't found a way. Could somebody help me or give me advice?
p.s. I don't use maven/ant so no need to advice me on that.
There's a bug in Eclipse where it won't export the last line of your manifest if you don't leave a trailing newline.
Export your project using the export to runnable jar of Eclipse and remeber to choose between these :
Extract required libraries into generated JAR : to inflate the referenced jar files and copy the classes into the generated jar
Package required libraries into generated JAR : to copy the referenced jar files as is into the generated jar
Copy required libraries into a sub-folder next to the generated JAR
See here
I'll try to be clear and concise on this.
i have a jar file of a project which is working perfectly. Now I need to make some changes to the application so i extracted that jar using this command.
jar xf jwire.jar
the files extracted are
META-INF (containing manifest file)
Resources (containing pictures used in application)
Jwire (containg classes and java files)
.classpath
.project
manifest.mf (another manifest file with some other path to main class)
i also added two empty folders src and bin here on somebodys suggestion.
now i'm trying to create the jar file again using all these folders.
Without making any type of changes I'm trying to rebuild this jar using the following
jar cf newjar.jar G:\Project1\project
NOTE:- I am guessing it's the right way to build the file. Please point if it's not right.
G:\Project1\project is the path to above mentioned files and folders.
The jar created using this is of size 729kb while the earlier one had 711Kb and when I run it using the following command.
java -jar newjwire.jar
I get the following message
no main manifest attribute, in newjwire.jar
Next i tried extracting this newjwire.jar file in order to see its manifest file. I got this folder META-INF containing the MANIFEST.MF file. it didn't have the path to the main class , So I edited it and put the modified file back on using the following command
jar uf newjwire.jar META-INF/MANIFEST.MF
when I run this jar, I get the following message
Error: Ivalid or corrupt jarfile newjwire.jar
What am I doing wrong? Am I building the jar file the right way? I used eclipse juno too and it gave the same message to that mainclass is missing. There is a main class consisting the main function. Is this something has to do with My orignal jar having two MANIFEST file.
I hope the problem is understandable. Clear and detailed answers will be appreciated.
you're supposed to update JAR files by jar uf jar-file input-file(s)
see this link: http://docs.oracle.com/javase/tutorial/deployment/jar/update.html
According to this page you need to EITHER have Manifest.txt present when you create or update the JAR, or use the e option to specify the main class. Probably the latter would make more sense in your case.
jar cfe newjar.jar mypackage.MainClass G:\Project1\project
I am trying to export jar of a project via eclipse
when I run that jar it gives error "failed to load Manifest attribute"
although I give main-class-name in manifest file but it is not working
I put following in Manifest class
Manifest-Version: 1.0
Main-Class: HangMan
For additional information: directory structure of Main class is
"/TestHangMan/src/test/HangMan.java"
what I am doing wrong?
EDIT: I forgot to mention, It(HangMan) is an Applet.Apologies!
Try exporting the Project as "Runnable Jar" instead of "Jar". It will configure your Manifest for you just fine. Im not 100% sure, where that Error comes from, but I think it is because it is missing the classpath for your jar.
There is a simple way to export simple Java programs as runnable JARs from Eclipse:
Remove the MANIFEST.MF
Move HangMan.java to the src folder (that's where your final code should be located)
Run your program once inside of Eclipse to create a launch configuration.
Choose File->Export->Java->Runnable JAR File
In the dialog Runnable JAR file Export choose the correct launch configuration and destination. If you are not using any 3rd party libraries leave the rest as a default.
Try running the JAR, on Linux for example with
java -jar $HOME/tmp/HangMan.jar
Good luck!
Update:
OP's HangMan is a Java applet (see comments) :-).
I am trying to run my jar file on a Mac (Haven't yet tried on any other platform). When I run using java -jar MyApp.jar I get the following error
Stacktrace:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at tabalchi.MyLogger.getLogger(MyLogger.java:51)
at tabalchiApp.TabalchiApp.printSystemProps(TabalchiApp.java:117)
at tabalchiApp.TabalchiApp.main(TabalchiApp.java:37)
So, as you can see the main class is recognized.
This is the manifest file.
--->
Manifest-Version: 1.0
Class-Path: . jars/log4j-1.2.16.jar jars/jfugue-4.1.0-20120125.jar jars/gervill.jar jars/AppleJavaExtensions.jar
Main-Class: tabalchiApp.TabalchiApp
SplashScreen-Image: tabalchiApp/resources/splash.png
<---
And the folder structure in the jar file as follows.
--->
META-INF/MANIFEST.MF
jars/AppleJavaExtensions.jar
jars/gervill.jar
jars/jfugue-4.1.0-20120125.jar
jars/log4j-1.2.16.jar
tabalchiApp/TabalchiApp.class <-- this is the main class
tabalchiApp/otherClasses.....class
<---
I have read many posts about running .jar file but none of the solutions have worked for me. I would really appreciate your help on this one.
I am creating the jar file by exporting from eclipse. If I export to a runnable jar file then I cannot control the making of the manifest file. I need to add the splash image in the manifest file. And I am having some other issues with the runnable jar export. Hence this path.
It seems that log4j is missing.it is expecting jars/log4j-1.2.16.jar in class path .
jars/log4j-1.2.16
should be under folder structure.
jars/log4j-1.2.16.jar
In which directory are you trying to use:
java -jar MyApp.jar
You can specify the packages/directories in the classpath to be sure they are found.
Ok, so according to this link,
http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html
The Class-Path header points to classes or JAR files on the local network, not JAR files within the JAR file or classes accessible over internet protocols. To load classes in JAR files within a JAR file into the class path, you must write custom code to load those classes. For example, if MyJar.jar contains another JAR file called MyUtils.jar, you cannot use the Class-Path header in MyJar.jar's manifest to load classes in MyUtils.jar into the class path.
So, it seems I cannot include other jar files in my jar file.
I am currently trying to make a Jar with all my libraries included.
What I have done.
I have created folders like this :
main folder
class (which contain all my classes)
ressources (containing all my libraries : mongo, jedis...)
MANIFEST.MF
My main class is named process.
My manifest is like this:
Main-Class: process
Class-Path: ressources\commons-pool-1.5.6.jar ressources\jedis-2.0.0.jar resources\mongo-2.6.3.jar class
I have generated the JAR with this command :
jar cvmf MANIFEST.MF process.jar class/*.class ressources/*.jar
My problem : When executing the JAR I have still the message
Exception in thread "main" java.lang.NoClassDefFoundError: process
Any ideas ?
Are you using eclipse? If yes, it have an option in export to export libraries together with jar..
with netbeans, I dont know how to do it.
You could build your jar with Ant using zipfilesets to copy in the content of the other jars (rather than the jars themselves), or you could take a look at jarjar which does that and more.
Eclipse: You have to add the external jar files to the build.properties, otherwise they are no tpart of the generated jar file.
Ar the libraries included in the jar file, you have generated?