eclipse does not add classpath to manifest file - java

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

Related

jar file works in eclipse folder but not out of it.Main class notfound

My groovy (ant1.8.1 for build)project was build in jdk1.5 and now i am making some changes and upgrading to jdk1.8 .
When i build and make jar ,it works fine from the folder where code is in eclipse.
but when copy that jar and try to run get below-
Error :could not find or load main class Run.
Rest all jars are as below(same as used in jdk5)
groovy-all-1.6.9.jar
commons-codec-1.4.jar
commons-httpclient-3.0-rc4.jar
commons-logging-1.1.1.jar
commons-net-2.0.jar
lib/log4j-1.2.15.jar
jtds-1.2.5.jar
httpmime-4.0.1.jar
When you say "run", I understand you mean something like:
java -jar MyJar.jar
You should check your MANIFEST file inside the JAR and make sure your Main-Class is defined as you need.
Main-Class: pakage.name.ClassName.class
And the corresponding pakage.name.ClassName.class exists in your jar file (or is included in any of the libraries accessible through classpath)
Check this anyway Setting application entry point

How to package required external libraries AND sources in Eclipse

I have an issue that is really annoying right now.
For a school project (that is due on monday :( ), I have to submit a .JAR file that is a stand alone app and that includes sources.
However, in Eclipse, I didn't find how to export the sources and at the same time, include the required libraries.
My BuildPath is set up this way :
http://image.noelshack.com/fichiers/2014/19/1399746312-owp08.png
When I do :
Export as a runnable JAR file, everything works in my program but I don't have the sources inside the JAR
Export as a JAR File, I can add my sources, but when i try to run the JAR file, I have this exception :
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Here are my settings :
http://image.noelshack.com/fichiers/2014/19/1399746469-sans-titre.png
I really don't know what to do, I've been searching for hours now, can someone help me ?
Thank you in advance.
Regards,
Azsde.
Well, the short answer is that eclipse doesn't support doing that directly. This is why most people use other tools such as Ant or Maven in their projects, rather than relying on the IDE.
You can work around eclipse's lack of an export source option in the runnable jar export wizard in one of two ways:
You can create a runnable jar and then manually add your source files to it
You can create a normal jar which includes your source files and add a MANIFEST.MF file to it.
Adding source files manually
This is what I would normally consider a terrible option, but since this is a homework assignment, there are two mitigating factors:
this is a one-off
you are short on time
If you have neither the time nor inclination to learn the details about manifests, I would recommend this option.
Adding your own MANIFEST.MF
As you may have noticed, even when you select the option to have eclipse generate your manifest in the export wizard, your jar file won't actually run. If you open up the 'normal' jar file and look at the generated manifest file it will look something like this (for a simple HelloWorld program using one third party library):
Manifest-Version: 1.0
Main-Class: HelloWorld
Whereas if you open up the manifest file for an exported runnable jar it will look something more like this (for the same program):
Manifest-Version: 1.0
Rsrc-Class-Path: ./ commons-lang3-3.3.1.jar
Class-Path: .
Rsrc-Main-Class: HelloWorld
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
As you can see, the generated manifest file is failing to include support for third party libraries.
What you would need to do in this case is write your own manifest file and keep it as a resource in your project. Then do a normal jar export, and on the last page of the wizard select the Use existing manifest from workspace option, and point it at your own manifest file.
This will have the advantage that you can export a new runnable jar whenever you like, including your source files, and without requiring manual tinkering each time.
If you're interested in working with manifest files, there's a good tutorial on oracle's website here that can help you get started:
http://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html

Jar file when extracted and rebuilt, isn't working

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

Java - jar with librairies included

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?

How to set classpath in manifest file , while creating JAR from eclipse?

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.

Categories