I have a program that i wrote with 3 java files but it uses images and text files in other folders, is there any way to put it all in any jar file or exe or something similar? Im using dr java. this is what it looks like now screeenshot
You can compile them to classes and them join them to one (executable) JAR file as described here: http://docs.oracle.com/javase/tutorial/deployment/jar/build.html
Edit: Eclipse has a feature to export (right click on project/Export.../JAR) to a jar file right away.
Related
I am sorry if this question is placed wrong, but considering it is about jars and Java I figured it would probably be the closest to my subject.
I have a Java program of which I have made, this program I am going to distribute for Mac and Windows. To do this for Windows I have used Launch4j, which works without any issues. Now the problem is that when I try to convert the jar into .app for Mac, it doest work, the app just opens and then closes right after. I suppose this is because when converting to Mac .app using Appmaker it doesn't include the external libraries I have used for the program. Because of this I am now wondering how I would add the external libraries to the .app file like I have done on the .exe, where I have just added the .lib folder with all the external library jars into the folder where the .exe is in.
I have tried adding the .lib folder to the content folder which is created for the .app file, but that doesn't work, I have also tried adding it to the ressource folder within the .app file.
One of the options I have found myself is to combine all external libraries and the actual program .jar file into one. It just seems very difficult and really I don't need it to be just one combined .jar, if it can be included in another way.
Not sure of Appmaker but can do something like an uber jar, i.e. a single jar that contains all the classes, basically take all the jars unzip them to a signle folder and then jar them up again.
Not sure what you are using to build but maven has a maven shade plugin that does exactly this.
This question already has answers here:
How do I make a JAR from a .java file?
(8 answers)
Closed 6 years ago.
I just have some (134) .java source files with me and I'm pretty sure that contains all the necessary code!
I want some quick tutorial to compile this program into a .jar file.
(I'm on a windows platform btw)
I have tried javac and jar commands. I got my .jar file but it's not opening!!!
Thanks in advance!
Best practice is to make use of Ant/Maven/Gradle kind of build program tools that can take care of creating Jar files.
Other way is to just make use of Eclipse's feature for exporting the project as a light weight Jar file or Runnable Jar file(which includes dependencies).
Place all the files you want to include in the JAR file inside a
single folder.
Open the command prompt in Admin Mode
Navigate to the folder where you stored your files.
Set the path to the directory of the JDK bin. You will need to run
the jar.exe utility to create a JAR file, and that file is located
in the bin directory.
Create the JAR file.
The format of the command line for creating the
JAR file looks like this: jar cf 'jar-file'.jar input-file(s)
You can use WINRAR.
right click on file (put inside all your .java files) and compile by using winrar;
choose format .zip (important)
and save filename.jar (important)
I have this, perhaps, easy problem, but I don't know how to handle this.
I have my Java program and it works pretty well when I call it via terminal (Java command).
The program uses 4 text files from the hard disk which can't be added as resources to the project.
How to do this right so I could build jar file only with main class and files from hard disk (first one is a config file and it has paths to other files so the program knows where they are)?
I'm using IntelliJ IDEA 14.1.4 on Arch Linux.
I did it based on this blog, but it's not working without txt files in src folder.
Also "jar cvf" command builds jar file, but it's not working outside my computer (for example on windows or OSX).
Can anyone help me?
I prefer step by step instruction so I would understand what is going on in here.
I recommend to build your application with Maven and create a Maven Assembly which contains your JAR file as well as the config.txt file.
I am trying to create an executable jar file that a user can just click on and execute the code. I have done some research but almost all of the examples are for single files. I currently have all my classes and images being used in my files in a folder. My images exceed the default java memory space and thus I have to run my code with -Xmx500m.
How can I create an executable jar that will go into my folder and run my program from there? Any help will be greatly appreciated!
Just use jar command to create the jar. You may need to link this type of file to Java so that it can be run by clicking on it in Windows. Something like this-
jar cvf test.jar <path to your classes / resources>
I am trying to create an executable jar file that a user can just click on and execute the code
Use Java Web Start to deploy it.
Put all the images and other media in Jar files mentioned in the launch file and they will be downloaded when needed. JWS also has facilities to adjust the memory allocated to an app.
I recommend using https://netbeans.org/ to build your project. Once built it will create the jar for you. You are also able to set compile settings such as the amount of ram you need.
See the following directions https://netbeans.org/kb/docs/java/quickstart.html#build
Is there a way to extract the source code from an executable .jar file (Java ME)?
Use JD GUI. Open the application, drag and drop your JAR file into it.
You can extract a jar file with the command :
jar xf filename.jar
References : Oracle's JAR documentation
I believe this can be done very easily. You can always extract the source files (Java files) of a jar file into a zip.
Steps to get sources of a jar file as a zip :
Download JAD from http://techieme.in/resources-needed/ and save it at any
location on your system.
Drag and drop the jar for which you want the sources on the JAD.
3 JAD UI will open with all the package structure in a tree format.
Click on File menu and select save jar sources.
It will save the sources as a zip with the same name as the jar.
Hope this helps.
The link is dead due to some reason so adding the link from where you can download the JDGUI
Your JAR may contain source and javadoc, in which case you can simply use jar xf my.jar to extract them.
Otherwise you can use a decompiler as mentioned in adarshr's answer:
Use JD GUI. Open the application, drag
and drop your JAR file into it.
I know it's an old question Still thought it would help someone
1) Go to your jar file's folder.
2) change it's extension to .zip.
3) You are good to go and can easily extract it by just double clicking it.
Note: I tested this in MAC, it works. Hopefully it will work on windows too.
Do the following on your linux box where java works (if u like the terminal way of doing things)
cd ~
mkdir decompiled_code && cd decompiled_code
// download jar procyon from https://drive.google.com/file/d/1yC2gJhmLoyE8royCph5dLEncgkNZXj58/view?usp=sharing
java -jar procyon-decompiler-0.5.36.jar /Path/to/your/jar -o .
NOTE : as #Richard commented "this may be illegal depending on whether you own the copyright to the jar, the country you live in and your purpose for doing it."
Steps to get sources of a jar file as a zip :
Download JD-GUI from http://java-decompiler.github.io/ and save it
at any location on your system.
Drag and drop the jar or open .jar file for which you want the
sources on the JD.
Java Decompiler will open with all the package structure in a tree
format.
Click on File menu and select save jar sources. It will save
the sources as a zip with the same name as the jar.
Example:-
We can use Eclipse IDE for Java EE Developers as well for update/extract code if require.
From eclipse chose Import Jar and then select jar which you need. Follow instruction as per image below
AndroChef Java Decompiler produces very good code that you can use directly in your projects...
Above tools extract the jar. Also there are certain other tools and commands to extract the jar.
But AFAIK you cant get the java code in case code has been obfuscated.
suppose your JAR file is in C:\Documents and Settings\mmeher\Desktop\jar and the JAR file name is xx.jar, then write the below two commands in command prompt:
1> cd C:\Documents and Settings\mmeher\Desktop\jar
2> jar xf xx.jar
-Covert .jar file to .zip (In windows just change the extension)
-Unzip the .zip folder
-You will get complete .java files