Manifest classpath is not working - java

I have created one manifest.jar which contains the jars that needs to be added in classpath for some other Jar. I tried using relative classpath as well in my manifest.mf but still these jars are not getting added in classpath or that jar which needs these jars is not picking the jars from manifest.
the manifest looks like :-
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Class-Path: abc.jar adc1.jar ../abc2.jar ../abc3.jar ../../lib/abc4.jar
So if my jar say "My.jar" needs these these jars in classpath. And i have created a manifest.jar from above manifest.mf.But still it is not picking these jars.

A possible reason is described in http://docs.oracle.com/javase/tutorial/deployment/jar/modman.html
Warning: The text file from which you are creating 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.

That's not allowed.... a jar can't contain other jars (if not exploded) look at: ClassPath in manifest does not work

Related

Java manifest file altered after exporting project

This question is a follow up of this and this question. I've placed the META-INF/MANIFEST.MF file as suggested to /src/main/resources and exported the project using the following MANIFEST.MF file:
Manifest-Version: 1.0
Main-Class: org.fiware.kiara.generator.kiaragen
there is a new line after the Main-Class entry before the end of the file. The artifact configuration is bellow:
The MANIFEST.MF file in the .jar file is different from the one specified in the resources directory:
$ cat META-INF/MANIFEST.MF
Manifest-Version: 1.0
Created-By: 1.5.0_13 (Apple Inc.)
Why is the Main-Class entry removed?
Simple - it is done due to the build cycle.
First your sorces gets compiled along with your manifest from the resources, second maven writes new manifest, and it gets simply overriden.
If you want to pust some custom stuff into your manifest, and you use Maven, you should rather modify your POM file to create proper manifest insteed of putting one in the resources.
Check following
https://maven.apache.org/shared/maven-archiver/examples/manifestFile.html for custom manifest includement.

eclipse does not add classpath to manifest file

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

Where will the jar be loaded up from in this situation?

This site:
http://pic.dhe.ibm.com/infocenter/wmqv7/v7r1/index.jsp?topic=%2Fcom.ibm.mq.doc%2Fjm10330_.htm
says that
The manifest of the JAR file com.ibm.mqjms.jar contains references to
most of the other JAR files required by WebSphere MQ classes for JMS
applications, and so you do not need to add these JAR files to your
class path.
So in the MANIFEST of my jar I have the following manifest classpath:
Class-Path: /opt/mqm/java/lib/com.ibm.mqjms.jar
In the com.ibm.mqjms.jar, it contains the following MANIFEST classpath
Class-Path: jms.jar com.ibm.mq.jmqi.jar dhbcore.jar rmm.jar jndi.jar l
dap.jar fscontext.jar providerutil.jar CL3Export.jar CL3Nonexport.jar
My question is: when the com.ibm.mqjms.jar starts looking for the jms.jar (or other jar),
where will it be looking ? (or at least looking first?
In the jar file itself,or on the /opt/mqm/java/lib
It will be looking in the directory where com.ibm.mqjms.jar is present. This makes it easier for the user as one need not know the dependencies of com.ibm.mqjms.jar ... Just ensure that you don't move individual jars out of that directory.
Some more details here: http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html

"Failed to load Main-Class manifest attribute from" a jar on the class path

So I have a java application that requires 2 jars as dependencies. One of the 2 dependencies is a java library I wrote called VT Access, and it does not have a main class. The other dependency jar is jsoup.
So I export my java application including this two jars on the class path from eclipse using the Manifest:
Manifest-Version: 1.0
Main-Class: vt.access.workshop/UI
Class-Path: "C:\Users\ethan\Documents\ACTUAL My Documents\Programs\VT Access API workshop\Dependencies\*"
Now when I go to run the resulting jar I get the error:
Failed to load Main-Class manifest attribute from
.\VT Access.jar
So I don't get what could be the issue, why does this program care if one of it's dependencies has a main-Class?
btw the manifest for Vt Access is here:
Manifest-Version: 1.0
Class-Path: "C:\Users\ethan\Documents\ACTUAL My Documents\Libraries\Java Libraries\jsoup\jsoup-1.6.3.jar"
Your class name is invalid:
vt.access.workshop/UI
should be
vt.access.workshop.UI
Moreover, I'm not sure you can use absolute paths in the classpath, and I'm even less sure you can use wildcards. And I'm also pretty sure the classpath is not transitive, so you should use relative path, and ad all the jar files your jar depends on in the classpath:
Class-Path: jsoup-1.6.3.jar vtaccess.jar
If you add these libraries to a subdirectory, use foward slashes and not backslashes. And remove white spaces from the jar file name:
Class-Path: lib/jsoup-1.6.3.jar lib/vtaccess.jar
See the Java tutorial for more information.

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