adding files to a executable jar file - java

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.

Related

Is there an option for intellij to build directories outside the JAR file?

So what im trying to do is to build a JAR artifact which should include the necessary libraries as well as directories which are outside of the JAR file and can be looked at in the explorer.
I have already tried to add directories to the artifacts but these get put into the JAR file in a folder which i cant access later when converting it to a exe using launch4j.
Is there an option in Intellij to exclude directories from building into a JAR?
Edit: I want the output directory like this
Directory Structure

How to use Jar file As a Java project in Eclipse

I have a jar file of an existing project. I want to write Junit test cases for each class in that project. To do that, I want to import that jar file as a java project in Eclipse so I can start new development of the same code. Is it possible to import a .jar file the same way we did for a .war file, and start developing the web project? If so, how?
A .jar file is just a .zip file containing all the class files of your java project. If the source files are included in the .jar file, you can unzip it and add them in eclipse. If they aren't, then you can't do what you want to do.
If you have source files in your jar i.e .java files along with your .class files, then rename your jar to zip and unzip the files. These java files can now be manually copied under src folder in eclipse.
Once your modifications are done, the new jar with your modifications can be created like this -> Right click on project ->export->Java->Jar option in eclipse. Or you can use ANT/Maven or similar build tool.

How to create a jar file of a java project which internall uses some external jars

I want to create a jar file of my project which is internally using some other external jars.
Basically what I am expecting is a single jar file which has all the class files and external files in it.
can someone help me in this
If your classes use external jar files then you need to enclose those jars into your jar file.
Right click on the project in eclipse then :
Click on 'export'->'Runnable Jar`
Here: Make sure you select 'Extract required libraries into generated JAR'
This will extract all the libraries present on the classpath of your project. into the exported jar file

Netbeans: how to create an executable .jar file with all libraries and resource files included?

I tried clean and build and found a .jar file in the dist directory. However, the libraries and resource files the program needs to run properly are absent in the .jar file. One workaround is put all libraries and resource files somewhere in the same directory or sub-directory of the .jar file. It is very inconvenient. How can I inject everything into the .jar file?
See the NetBeans documentation on Packaging and Distributing Java Desktop Applications, especially the section on Running and Distributing the JAR File.

creating jar file for java application

i have created a java application which uses data from its config folder and , it also uses third party jar files those are located in lib folder, could anyone tell me how to create jar file for this project with the content stored in config file and lib folder.
i tried creating jar using eclipse export functionality. when i run this jar file, it says it can not find the third party libraries that i have used for this project and configuration file.
thanks in advance for any help
You can create a Runnable JAR in Eclipse 3.4+ in the Export wizard selection dialog (right click on a project and go to Export...) using an existing launch configuration which will incorporate the libraries or repack them. Config files should be readable from the same directory as the runnable jar is located. If you need any help with loading these in, just ask :)
(source: eclipse.org)
You have two options
include the stuff in the third-party jars in your jar
provide access to the jars on the classpath when you run your jar.
Both have their benefits and their drawbacks.
Java does not support putting JAR files inside executable JAR files, so you can't just put your third-party library JAR files inside your own JAR - Java won't be able to find them.
If you don't want to distribute your application as a whole bunch of JAR files, you can use a look such as One-JAR which will build a JAR file for you that contains your own classes plus the classes of the third-party libraries that you're using.
To learn more about how to package a program in an executable JAR file, see Packaging Programs in JAR Files in Sun's Java Tutorials.
If you use netbeans just by click on "build" a jar file will show up in the "dist" file in your project directory

Categories

Resources