I know this question asked many times but I can't find my answer from older question .I have four packages an I want to create jar file from this packages my main program is in main package . I use this statement like so :
jar -cvfm app.jar manifest.txt *
When I saw the content of a jar file my sources (.java) also exist in the jar file but I want just to have .class file in my jar file .How can I solve this problem?
You may change the command to:
jar -cvfm app.jar manifest.txt *.class
You missed the .class part. By using the wildcard * you've included everything.
Good Luck.
Related
I'am working on a python script , which involves few steps of creating a jar file.
However when i run the following lines of code i get the jar file created, having .java files and not .class files .
subprocess.call(['jar', 'cvf', 'process.jar','C:/my data/temp/process/src'])
Is there any way to get the jar file created with .class files similar to Export generated class files and resources checkbox in export jar dialog in eclipse .
Thanks
Make sure where is your *.class files located, I assume it is in bin directory or something:
subprocess.call(['jar', 'cvf', 'process.jar','C:/my data/temp/process/bin'])
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 have some java code written in a text file, now I want to create a jar file to use that file as a library in my android project. So what would be the best way to make a jar file from this point. Please note that I have some code written in a textfile and saved as a .txt. If I rename that file to .java and use this code
jar cf filename.jar file(s)
a jar file is created but when I decompile it in java decompiler it doesnt show the packages and that codes that's why I am unable to use it's methods. What would be the best way to do this? I need help
If you want to use the classes in your library they must be compiled and you have to manually create all the packages subfolders.
So :
1. Make a folder
2. Create each package subfolderds in it (com/foo/bar/xxx)
3. Compile each of your .java files and put them it the correct subfolders
4. Zip your folder and rename it with a .jar extension
But it is hard to do this by code, why don't create it with your IDE ?
Creating a jar File in Windows Command Prompt
Start Command Prompt.
Navigate to the folder that holds your class files:
cd \mywork
Rem -- Set path to include JDK’s bin. For example:
path c:\Program Files\Java\jdk1.5.0_09\bin;%path%
Rem -- Compile your class(es):
javac *.java
Rem -- Create a manifest file:
echo Main-Class: DanceStudio >manifest.txt
Rem -- Create a jar file:
jar cvfm DanceStudio.jar manifest.txt *.class
Rem -- Test your jar file by trying to execute it
Rem -- This will not apply for a library JAR file without any main
java -jar DanceStudio.jar
I've made a jar file for all my classes and yes it works. Although it's not running my custom GUI. I'd like to set the jar file to run my GUI before anything else, and from there the rest of the files will be executed.
How would I do this? Thanks in advance.
When I run it through the command prompt using
java GUI
it works, but I need to do this using a jar file as I want my class files obfuscated.
I presume you jave just .class files now and you want to create a .jar file.
To run a jar file you must add -jar after the java command.
Jar files are zip files which contain the classes, possibly resources and a manifest that tells which class has the main() method.
The jar command is used to create a jar file.
jar cvfm output.jar Manifest.txt *class package1 package2
and in Manifest.txt you should have this line:
Main-Class: MainClass
After that just run:
java -jar output.jar
I'm not very skilled in writing batch files and/ or java. I have a folder with several .class-Files and folders in it and I want to put them all into a executable .jar-File. I know that there is a tool called "jar - The Java Archive Tool", but that just won't work for me. My folder structure looks like this:
Folder "test"
File (a.class)
Folder "subdirectory"
File (b.class)
I want a executable .jar-File called file.jar. In this .jar should now be the file a.class and the folder subdirectory with the file b.class in it.
I don't get the .jar-Tool to run and the 7zip command line doesn't support .jars (I can't even add files to it). I want this to run from a .bat-File, so I just have to open the batch-file, it creates the .jar and puts the files in it and then closes itself again.
I hope you can help me and get what I mean.
If you have issues in executing jar command, then probably you would need to check if your path has been set correctly. You can verify if the path contains jdk location ( echo %path%) from command prompt. If not you need to update. Also you can verify using Javac -verbose command to see jdk is installed.
Once you have jdk path set, you can try below command to create jar
Jar -cf myapp.jar * --> includes all files including files from sub folders.
If you want to run from batch, you would need to mention path before jar command. Ideal place for path is to configure as environment property.
Create a text file (and call it something useful like manifest.txt). In it, put the line:
Main-Class: a
(which should be called A by convention) and include a hard return at the end.
Then create the jar with:
jar cvfm file.jar manifest.txt *.class
or
jar cvfm c:\somedir\file.jar c:\somedir\mainfest.txt *
You could just put that line in a batch file called createJar.bat and run it if you only want to create files called 'file.jar'
hth