I "converted" the jar file into a zip folder
and then to a normal folder. I opened the MANIFEST.MF file with the text editor. Then I closed it and made the folder to a jar file. When I double clicked the jar file, it says "corrupted jar file". I don't know why; is it because I opened the MANIFEST file with the text editor or why?
In the future, you can use the jar command to remove files and add them back into a jar.
List all files in the jar:
jar tvf application.jar
Extract a file from the jar:
jar xvf application.jar path/of/file/to/extract
Add a file back into the jar:
jar uvf application.jar path/of/file/to/extract
MANIFEST files get a little special handling. If you want to add it back in:
jar uvfm application.jar mymanifest
Note: In all the commands above the v flag is used to provide verbose feedback from the command and can be omitted if you want.
If I understood right, your new jar contains a redundant folder because you zipped the folder, but what you had to do is to zip only content of that folder.
Related
i have a folder on my desktop named theme.I am new to Linux totally.
So what do I do to create a jar file from this folder?
I found this example but It doesn't work for me.
jar -cvf theme.jar
You are failing to specify the input files for the jar.
Navigate to the theme/ directory using the cd command in Terminal. If you want to include everything in this directory in your jar file, use the following command.
jar cvf theme *
Note that the * character (wildcard) indicates you want to include all files and subdirectories.
See: http://docs.oracle.com/javase/tutorial/deployment/jar/build.html
Jar files are really just zip files, renamed to .jar. Just use any folder zipping tool (such as the zip command).
zip -r theme.jar /path/to/desktop/theme
Can anyone please tell me how to add a class file into particular package inside a JAR file using command prompt.
Example: Test.jar has a packaging structure com.test
Now I want to add a class file called Test.class into com.test package of Test.jar file.
Your help will be highly appreciated.
You can update a JAR file by passing the 'u' argument and supplying the JAR and file you want to add:
jar uf Test.jar com/test/Test.class
More info about this option here.
jar uf jar-file input-file(s)
In this command:
The u option indicates that you want to update an existing JAR file.
The f option indicates that the JAR file to update is specified on the command line.
jar-file is the existing JAR file that's to be updated.
input-file(s) is a space-delimited list of one or more files that you want to add to the Jar file.
Any files already in the archive having the same pathname as a file being added will be overwritten.
Ref : http://docs.oracle.com/javase/tutorial/deployment/jar/update.html
I would like to ask a question if there is a way to copy a file(i.e. an image) to a .jar file, because i want to deploy a program and i created folders along with the source codes(they are in the same location as the source codes) and the folders are inside the jar file (i used Netbeans to create the jar file)..... Now what i want is i would like to copy files choosen by a JFileChooser to the folders inside the jar file????
Any idea is heartily accepted..!!! Thanks in advance????
P.S.:
I already tried searching the net for answers but all they know is how to copy the file inside the jar file to another directory......
Suppose that you want to add the file images/image1.gif to the JAR file.
jar uf <fileName>.jar images/image1.gif
To change the directory use -c
jar uf <fileName>.jar -C
in this command
jar uf jar-file input-file(s)
In this command:
The u option indicates that you want to update an existing JAR file.
The f option indicates that the JAR file to update is specified on the command line.
jar-file is the existing JAR file that's to be updated.
input-file(s) is a space-delimited list of one or more files that you want to add to the Jar file.
Related Docs
A JAR file is a ZIP compressed file.
See this S.O. answer for a solutiion to add files to an exisiting ZIP archive: Appending files to a zip file with Java
I was trying to, for debugging purposes, inject a (hacked) META-INF/MANIFEST.MF file into a jar. I created a META-INF dir at the same level where the jar is and created my MANIFEST.MF file in it. Then, per this tutorial:
jar uf myjar-with-dependencies.jar META-INF/MANIFEST.MF
which executed without error but just wiped out the existing manifest without replacing it. I know it because I ran:
jar tf myjar-with-dependencies.jar | grep MANIFEST
which, before the update, returned the found file in the jar but does not now after the update.
"jar ufm" is what you're after. The m argument specifies that you're providing a manifest file.
jar ufm <yourJar> <yourManifest>
Otherwise it just treats it as a regular file which will end up getting stomped on when it generates the default manifest file.
A Jar is just a zip file. You can open it up using any tool you would normally use to open a zip file and then just place your file inside of it where you want.
How do I convert:
class file to jar file using cmd?
class file to exe file?
jar file to exe?
Can I convert exe file to jar file?
Class files to jar files
Usage: jar {ctxu}[vfm0M][jar-file]
[manifest-file] [-C dir] files ...
Options:
-c create new archive
-t list table of contents for archive
-x extract named (or all) files from archive
-u update existing archive
-v generate verbose output on standard output
-f specify archive file name
-m include manifest information from specified manifest file
-0 store only; use no ZIP compression
-M do not create a manifest file for the entries
-i generate index information for the specified jar files
-C change to the specified directory and include the following
file If any file is a directory then it is processed recursively. The manifest file name and the archive file name needs to be specified in the same order the 'm' and 'f' flags are
specified.
Example 1: to archive two class files into an archive called classes.jar:
`jar cvf classes.jar Foo.class Bar.class`
Example 2: use an existing manifest file 'mymanifest' and archive
all the files in the foo/ directory into 'classes.jar':
jar cvfm classes.jar mymanifest -C foo/ .
Convert jar files to .exe file
1)JSmooth .exe wrapper
2)JarToExe 1.8
3)Executor
4)Advanced Installer
Convert .class to .exe is discussed in length here
You must have missed this. Please look into Java Archive (JAR) Files Guide.
And surely missed Real's How to for it Make a JAR executable There are multiple wrappers that do this work (converting Jar to exe, platform specific). You just need to search in StackOverflow for Jar exe
To convert (actually, package) .class files into .jar files, you use the jar tool. You can then generate a .exe file from the .jar using tools like Launch4j, JSmooth or several other packages (search the web for "jar exe").
If you are using Netbeans IDE, then creating .exe file from .class file won't take much time. In IDE, create a new project and put your java program in this project. Now follow these steps-
Right click the project and choose properties.
Choose run from left panel and enter the main class(in which main method is defined) in right panel.
Again right click the project and choose add library. Select swing layout extensions. Click add library.
4.Now select clean and build from run menu in your IDE. Make sure that you have already set your this project as main project.
Open the CMD and set the directory to your project. Go to "dist" > and type java -jar jarname.jar.
Your program is running in cmd now.
Open launch4j and provide the information required.
Run and enjoy your application.
Create jar file using command line. Answer in http://download.oracle.com/javase/tutorial/deployment/jar/build.html
Class to exe. Answer in http://www.javacoffeebreak.com/faq/faq0042.html
Jar to exe. Answer in http://viralpatel.net/blogs/2009/02/convert-jar-to-exe-executable-jar-file-to-exe-converting.html
Converting exe to a jar file is possible. But involves reverse engineering to discover what is in the exe, extract and do whatever you want with it. In my opinion, is not worth at all.