I experimented so heavily on netbeans, and I got a way to create .bat file to run java project on Windows OS. the .bat file is inside a zip file. The zip file is structured like this, in a netbeans java project.
inside the zip, is structured like this:
[folder name]->[folder named "bin"]->[2 files]
the [2 files] is:
a file named after the project name, without file extension. in this
case is "Replicator3". this is a "start up script for UN*X".
a bat file. in this case is "Replicator3.bat".
beside bin folder, there are also lib folder as you can see on picture above. the lib folder contains project .jar file and 2 .jar of library files.
I made this zip file and its content with netbeans, but I forgot how to remake this zip file. I reinstall Windows OS and now I cant remember how I did this.
Please help me create this zip file in netbeans. If I remember correctly, I did this on Netbeans 8.2.
Thank you in advance.
From my observation, that zip package might created using gradle
I have simple Java Application and trying to create JAR to distribute using eclipse.
But when I look inside JAR it doesn't contain the test.txt file. I created JAR as Export>Runnable JAR File
You need to put that file into one of your source folders (such as src). Only those get copied into the jar file (by default).
See the following image:
Choose the file which you want to add in jar file.
I have a mayapp.war which is deployed in tomcat server. I want to replace a file(test.properties) which resides inside myapp.war with another file(test.properties) and this file resides outside myapp.war. I want to do this stuff using a cron job. will appreciate any kind of help.
A war file is just a zip file. You can use any zip command tool to replace a file or you can use the jar command from the JDK.
Use following command:
jar uf myapp.war test.properties
Hi im busy on a application that decompiles a jar the pastes files into the folder of the decompiled jar, it then compresses the folder into a jar.
Decompiling and copying works, but i can't manage to get the folders contents to be jared (compressed into jar), i did about 3hrs research and found only outdated methods. please help.
-Regards
marko5049
EDIT MORE INFO:
I apologize i mean i cant get my application to turn a folder into a jar file, my application is an modification installer for a jar file. and it extracts the jars files, then adds the modification and then, is supposed to then turn the folder back into a jar file so that the modification is installed. The jar file is not executable.
This worked for me for a MAC OSX:
Open Terminal at the folder with the jar file and run the following commands
unzip mylib.jar -d jarfolder
//You can then change whatever you need and finally run the command below
jar cvf mylib.jar -C jarfolder/ .
Given that you want to create the JAR through code; you can use JarOutputStream for that. There is an example at this link that contains code to create a JAR file given a File[] containing all the input files.
As for creating the list of files given a starting input path, see Recursively list files in Java.
You could either build a list of files then just use code like in the above example, or you could recursively scan files and add them to the JAR as you go.
If you are using Java 7 and you know your users are too you can also use Files.walkFileTree() with a FileVisitor that adds entries to the JAR as it visits files.
Original answer before OP clarified:
Is there something wrong with:
jar cf my-application.jar folder1 folder2 folder3 etc
The JDK comes with a jar utility to create JAR files.
You can read an official tutorial on it here: Creating JAR Files. It is very straightforward.
If you want to create a runnable JAR, you can create a manifest file that has the main class and other options in it. The linked tutorial describes that process.
The short answer is, ZIP the folder, then rename it to a JAR file.
for windows just make the folder as winrar file.,
to do this right click the folder and click "7 -zip" then
choose "add to foldername.zip".
now a rar file is created with the same folder name.
Then open the cmd in current folder directory
type "mv foldername.zip foldername.jar"
Now you got the executable jar file with your corresponding folder.
The easiest way to make it .. put your folder to C:\Program Files\Java\jdk1.8.0_221\bin and then reach till the same path from CMD then run this
jar cvf Name_your_jar.jar folder
Following command worked for me in Windows 10 and jdk-8u212
jar cf my-application.jar folder1 folder2 folder3 etc
You can put your files in a zip folder. Then convert the zip file into Jar format.A .jar extension file is a Java Archive format file. It is used to store a large amount of files into one single file. You can try a free online file converter without downloading a new software on your computer. There are various online file converters available on Google. I would recommend Convert zip to jar
I hope it helps.
I just found this question and its answers are more useful for your problem:
how to zip a folder itself using java
2 tips :
1、a jar is exactly a zip. So, you just need to zip your folder, and rename it to jar
2、be careful that you should zip your whole folder without changing the relative path of the files, but not just extract all the .class files and zip them together. Because when you run the jar, the class package should be consistent with its path.
I suggest trying to create a regular .ZIP file in Windows.
You need to get 7-zip in order to view the .JAR file you are creating. You should just paste contents into the .ZIP, then rename the file type from .ZIP to .JAR, this worked for me and I hope this works for you.
.JARs are basically .ZIPs created by the Oracle Java client, so you need special file viewing software such as 7-zip or WinRAR to view it for some reason.
You can also revert .JARs to .ZIPs by renaming the file type. You might have to mod your computer with RegeEdit or something to have access to renaming your file types.
I hope this helps.
Is there a way to extract/view the contents of a download jar file from the Eclipse?
If you add it the build path of a Java project you can browser a JAR file's contents in Eclipse.
I don't know if you can extract a JAR file's contents in Eclipse. (I don't understand why you would want / need to do that!) But you can extract a JAR file from the command line using the jar command ... or an ordinary ZIP file extractor.