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

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

Related

manifest Class-Path not honored in a Wildfly module

I'm trying to create a Wildfly Module for OpenText Documentum java client. Previously I was packing its jars to the .war file and my app was working, but they weight 23Mb.
In J2SE you usually just add the main jar which is dfc.jar and its dependencies are automatically added, because of Class-Path: entry in dfc.jar/META-INF/MANIFEST.MF. However, it doesn't seem to work in Wildfly 11: I created the module, made my webapp depend on it, but when I try to load the DfException class from the main jar Wildfly fails to find one of the dependencies which are in the same folder:
Caused by: java.lang.NoClassDefFoundError: org/aspectj/lang/Signature
at com.documentum.fc.common.DfException.<clinit>(DfException.java:710)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.foo.PrintClassloaders.printClassloader0(PrintClassloaders.java:50)
Is it possible to create this module without adding all the jars by hand?
Here's what I did:
module add --name=documentum.dfc2 --absolute-resources="C:\Program Files\Documentum\Shared\dfc.jar"
src/main/resources/META-INF/MANIFEST.MF:
Dependencies: documentum.dfc2
PrintClassloaders.java:
Class.forName("com.documentum.fc.common.DfException");
generated module.xml:
<module xmlns="urn:jboss:module:1.1" name="documentum.dfc2">
<resources>
<resource-root path="C:\Program Files\Documentum\Shared\dfc.jar"/>
</resources>
</module>
dfc.jar/META-INF/MANIFEST.MF:
Class-Path: All-MB.jar activation.jar aspectjrt.jar certj.jar commons-
codec-1.3.jar commons-lang-2.4.jar configservice-api.jar configservic
e-impl.jar cryptoj.jar cryptojce.jar cryptojcommon.jar dms-client-api
.jar jaxb-api.jar jaxb-impl.jar jcifs-krb5-1.3.1.jar jcm.jar jcmFIPS.
jar jcmandroidfips.jar jsr173_api.jar krbutil.jar log4j.jar questFixF
orJDK7.jar util.jar vsj-license.jar vsj-standard-3.3.jar xtrim-api.ja
r xtrim-server.jar
aspectjrt.jar is in the same folder. Why isn't it picked by the module classloader?
What you are trying there looks very strange to me. Modules (=Java libraries) belong into the modules folder and deployments should contain a deployment descriptor which lists all modules that it needs. In easiest case you only need the dependencies section inside the jboss-deployment-structure.xml file. See http://docs.wildfly.org/12/Developer_Guide.html#jboss-deployment-structure-file
Each module can contain multiple jar files and depend on other modules. When you take a look into some existing modules.xml files, you will see how it goes. Path names inside module.xml should be relative, otherwise you are not able to deploy them onto another computer with different folder structure.
You do not need any Manifest file for this.
Apparently, to add all the dependent jar files from the manifest Class-Path you have to explicitly create a <resource-root> element for each jar.
For cases when there is too many jars or there's a deep hierarchy I made a tool that parses the manifests recursively and prints the jboss-cli command to create the desired module.
Example:
C:\> java -cp org.foo.modulegen.Modulegen C:\some\main-jar.jar
Output:
--absolute-resources="C:\some\main-jar.jar;C:\some\jar2.jar;..."
https://gist.github.com/basinilya/15db9267ec753941d098cfd2f7ff844d
The tool tries to open each command line argument as a java.util.zip.ZipInputStream, finds and parses MANIFEST.MF with java.util.jar.Manifest and then does the same for each entry in the Class-Path attribute. It also ensures to not open the same jar file twice.

How to load a whole directory using Class-Path: jar manifest header? [duplicate]

This question already has an answer here:
Does the Class-Path in the MANIFEST.MF can only include jar Files?
(1 answer)
Closed 7 years ago.
If in the manifest for a jar file that needs to load non executable jars, I have the Class-Path: specification and then a directory holding the jars as the class path instead of a jar file. Will the manifest then load the whole directory or will it just fail?
Update:
I tried to use Class-Path: foo/* however it failed to load the foo directory. Does the manifest classpath not support regex>
As long as your foo directory contains only .class files, you can safely set the Class-Path: header like this:
Class-Path: foo/
Since you have non executable jars in it, you should use a build tool like Maven to generate the Class-Path: entry for you. The non executable jars will be dependencies of your Maven project.
Reference:
JAR : MANIFEST.MF Class-Path referencing a directory

"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.

Manifest classpath is not working

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

Creating a merged executable Jar from many jar files(used in classpath)

I have a desktop application , which is packaged as a self-executable jar file, but my code needs to access many jar files , which i have set in the class-path in the manifest file. But the problem that I am encountering is that all the jars to be used in the class-path I have to keep them in the same directory as my executable jar file.What I need is to somehow merge all the various jars so that I can specify this single jar in my class-path in .mf file.
The .mf file is-->
Class-Path: poi-3.7-20101029.jar poi-examples-3.7-20101029.jar poi-ooxml-3.7-20101029.jar poi-ooxml-schemas-3.7-20101029.jar poi-scratchpad-3.7-20101029.jar jfreechart-1.0.14.jar jcommon-1.0.17.jar jfreechart-1.0.14-experimental.jar jfreechart-1.0.14-swt.jar junit.jar servlet.jar swtgraphics2d.jar gnujaxp.jar iText-2.1.5.jar
Main-Class: gui/GUILauncher
Kindly suggest me a solution, so that I can achieve my objective...
You could specify a path to each at file in the manifest
Class-Path: lib/poi-3.7-20101029 ...
And store the library jars here.
While I like the idea of combining all he classes into a single Jar, you need to be careful of resources that might share the same path. We have this issue in our app, all our Jars contain a Version file we use as a marker and read via Class.getResources(...)
You need not keep all these jars in executable jar directory. Instead you could specify relative path of dependent jars in Manifest.mf file.
e.g.
You have kept your executable jar under bin folder and dependent jars under lib folder.
app-root
+
+ \bin
+ + GuiLauncher.jar
+
+ \lib
+ junit.jar
+ servlet.jar
Manifest.mf Classpath will be
Class-Path: ..\lib\junit.jar ..\lib\servlet.jar

Categories