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 been adding modifications to a Java application that runs on a server using an applet. On the server, there is just the jar file, and an index.html page that opens the applet.
Now, I am trying to test the new version of the app on my computer before putting it on the production server, and it doesn't work : the application doesn't connect with the MySQL DB (when I just run it from Eclipse it works, it is when I try to run the jar file from my browser that it doesn't work). I tried running the old app on my desktop the same way and it runs just fine, so I guess the problem is in my jar file.
I have opened the 2 jar archives to see what's inside, and here's what I get :
Old jar :
Different folders for the different packages of the app
bin folder
com folder
META-INF folder
org folder
.classpath file
.project file
java.policy.applet file
mysql-connector-java-5.0.8-bin.jar
And now, here is what's inside the new jar :
Different folders for the different packages of the app
META-INF folder
.classpath file
.fatjar file
.project file
java.policy.applet file
mysql-connector-java-5.0.8-bin.jar
settings.fatjar file
So my archive doesn't have the bin, com and org folders. It also has 2 additionnal files.
I don't know which settings should I use when exporting my jar in Eclipse to obtain the same content ?
Also, my new jar isn't signed, could this have something to do with my problem of database access ?
I'll answer my own question, as I found the solution :
The jar needs to be exported as a runnable jar
The option "extract required libraries into jar" must be selected
The jar must be signed (self signed works as it is an internal app, so no need to pay a certificate)
Now it works :)
While execute the jar file. i found this exceptions. But when i tried to double click the .jar file. It shows
if anyone know whats the error. just tell me..
Your jar needs the Jcalendar classes to be executed properly...
is the Jcalendar. jar in the classpath??
For those who Got this error "Java Exception Has Occurred" Try this
I tried the solution in Netbeans. While creating a jar file for swing applications. Your .jar file is placed inside the dist folder. Inside the dist folder you have one lib folder and your .jar folder.
Just select the two lib and jar files and copy and paste in some other new folder. And now you double click your jar file. now your jar file is working fine.
I have a big project and runs well in Eclipse. I build a runnable jar file by eclipse. When I put the jar file directly on the desktop it runs well, however if I make a new folder and move the jar file to the new folder, it does not work correctly, the output file is empty.. No errors appear.
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.