Run jar that depends on external jars inside JRE folder - java

Case: all external jar files are in the folder
/usr/lib/jvm/jre-1.8.0-oracle-1.8.0.151-1jpp.5.el7.x86_64/lib/ext
I need to run my executable JAR that uses these jar files internally. Do I need to specify them when explicitly starting my jar, or since they are inside the JRE directory, will they be automatically pulled up?

The jar files inside the jre folder will be found automatically because you must have set the path of java to the folder in the system path.

Related

Provide additional classpath on jar having embedded Tomcat

I have a executable jar containing an embedded Tomcat which is created thanks to tomcat7-maven-plugin: tomcat7:exec-war.
I need to provide an additional classpath for some Jar because I cannot include them directly in my executable Jar. How can I provide this classpath ?
I cannot execute export CLASSPATH before I launch my executable Jar because catalina.sh/.bat erase the CLASSPATH value.
I cannot provide a setenv.sh/.bat because the executable Jar is created by the maven plugin.
I cannot update property common.loader from catalina.properties because I don't have control on this file which is generated by maven plugin.
Note: I don't want to specify a hardcoded path to the lib in the executable Jar.
Actually whatever jar files are inside WAR file at WEB-INF/lib are in classpath for WAR file classloader.
So, you can package your additional jar into war.
I'm not familiar with maven tomcat plugin, but just look to its options. It must have ability to put additional jars into war file (maybe just through dependencies in compile or 'runtime` scope. It is a standard feature.
If your additional jar must be outside of war you have to give it in system classpath for Java when you run your executable jar (through -cp parameter, I guess). Or you can define path to it in the MANIFEST.MF file of your jar.

adding files to a executable jar file

so i currently have a built version of my javafx apllication, and it resides within my dist folder. within the dist folder is a folder for my apache derby database, a folder for the external libraries I'm using and the executable jar file.
I'm wondering is it possible to have my database and external libraries within the executable jar instead of being in seperate folders, as i'm giving this application to customers and would prefer to have it in a single jar file instead of a zipped folder.
jar files are read only file so you can't put your database files in a jar file.
You can use softwares like launch4j to create an exe of your jar and inno setup compiler to create a setup file of your application. So then you will be able to deliver it within a single file.
If the external libraries you are referring to are Java dependencies, and you are using Maven, you can package them into your program's Jar by using the Maven Shade Plugin. Then it is possible to programmatically create the folder where you will store the database during runtime, instead of sending an empty folder in the zipped folder.

Eclipse : Add jar file and not depend on local machine path

I'm working on Eclipse with a java project. In this project, I include a jar file. But when I include it, eclipse remembers its path base on local machine. For example : if I'm on Windows, the path will be C:\Document\... and if on Linux, will be /hqt/workspace.. for example.
Although, in project folder, I create a folder lib and copy jar file to here, hard link to this jar doesn't change. So, when I copy this project to another place that jar file doesn't same with my current local machine, jar file will be missed and must re-config again.
So, my question is : How can i include jar file and not depend on local machine path.
Thanks :)
Do not use "Add external JARs...". Put the jar in the "lib" forlder you have created in your project then add it to the classpath using "Add JARs...".

ANT Java-Jar task to include native DLL

I have a JAR library that needs a native DLL library to work properly (Scriptom/Jacob).
I added the JARs to my classpath in ANT. But I do not know how to add a DLL file so my compiled Java/Groovy files finds them (neither in a generated JAR, nor in an ordinary execution by java Main.class). They are all located in a project subdirectory libs.
How do I have to alter my ANT build file that DLLs are recognized by my application?
PS:
As it works properly in a configured Eclipse environment: Is it possible to extract a fully working ANT build file from an Eclipse Run Configuration?
You can't use DLL files when they're still packaged in the jar.
I suggest you create an application folder where your .jar will be located at and next to the .jar, put your DLL files there. In your application you will need to load your DLLs from that location.

Using JAR inside a jar

I created a JAR file from my java project.
Using Eclipse, I added a JAR as a referenced library in my own project.
However, now when I try to run my program's JAR using java -jar myProgram.jar, I get an exception stating that my referenced jar is not available.
So how can I create a JAR consisting a reference to a different JAR and make it work?
Right, an executable JAR cannot contain its own JAR dependencies.
You have to have the main class and classpath set in the executable JAR manifest, then package all your JAR dependencies along with the executable JAR in a relative directory structure that matches the manifest CLASSPATH. Reading this might help.
You need to use Eclipse's runnable JAR exporter. Since Eclipse 3.5 you've the following options when you rightclick project, choose Export > Runnable JAR file:
Either way, Eclipse should take care that you'll be able to run the JAR the way you want on the exported location.
See jarjar project. It is exactly what you are looking for. http://code.google.com/p/jarjar/

Categories

Resources