How to use Jar file As a Java project in Eclipse - java

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.

Related

Is there any tools help to reverse jar to java eclispe project

All, I have a jar file. and I know it is built from a swing project. Becuase I already view some source code of class files of the jar. I want to know if there exists any tools help to convert the jar back to the source project in the eclipse? Thanks.
http://jd.benow.ca
Drag and drop jar file into JD GUI decompiler
select File-> Save all sources
7zip will allow you to view the contents of the jar, including source files if they are there. Lots of decompilers exist to decompile the class files. My favorite is jd-gui (http://jd.benow.ca/).
You can also add a jar in Eclipse by right-clicking on the Project → Build Path → Configure Build Path. Uthen under tje Libraries tab, click Add Jars or Add External JARs and select the jar file. Alternatively you can add a lib directory to your project and put a copy of the jar there.
But as far as converting a jar file into an eclipse project, you could extract the files with 7zip or other tool, then import them into a new eclipse project.

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.

How can i make a executable Jar file with source codes attached in Eclipse?

I know how to make an executable Jar file in Eclipse.
but if I want to add *.java files in the jar file,
(when I want to CREATE a jar file),
are there any good ways?
or do I need to add them after Eclipse creates a jar file?

Deploy Eclipse 4.1 Project

I have create a simple program using Eclipse 4.1.. I wanted to build or deploy my project into a .jar. I also added external libraries in my project. I wanted the output same as in Netbeans with the .jar file and lib folder in the dist folder, but there should be also a folder named help and lang.. How can I do this with eclipse?!
Follow the steps provided here.
Or if you don't want to complex things up, select Runnable JAR file instead of JAR file set the directory where the .jar is to be written then click Finish.
Eclipse will create the [Project Name]_lib directory for the external libraries included in the project.

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