This question already has answers here:
How do I create a ZIP file in Java?
(2 answers)
Closed 9 years ago.
Is it possible to compile class file to jar file not using jar -cvf options.
I want to compile jar files by source code.
Cant somebody show me some example codes
A JAR simply is a ZIP file.
While I am not quite what you are trying to achieve, I can give you these hints:
Compiling: javac Hello.java
Creating a JAR: zip Hello.jar Hello.class
If you want to have a JAR containing your sources, you could as well run the above command with: zip Hello.jar Hello.java
Also note that, if you are using a build tool like for example maven, there are various plugins for suchs tasks such as 'assembly' (for maven).
Related
This question already has answers here:
How to make an executable JAR file?
(5 answers)
Closed 2 years ago.
hello someone could suggest me how to compile the java project that I attach to generate the sri.jar file that appears in the Readme file
//Project java to compile
https://github.com/joselo/sri
//command line where the sri.jar that I want to generate appears
java -jar sri.jar /path/sample/certificate.p12 cErTiFicAtEPaSsWoRd /path/sample/unsignedFile.xml /path/sample outputFile.xml
To create a jar file first thing that needs to be done is to compile the project using javac
javac -cp ./sri-master/lib/*: ./sri-master/src/sri/*.java -d ./out/
and then run the below to create the jar
jar cvfm xyz.jar ./sri-master/manifest.mf -C ./out/ .
This question already has answers here:
How does a jar file get executed? Do the classes get extracted somewhere?
(2 answers)
Closed 3 years ago.
Take a standalone executable jar file for example, in which we generate from our application with all the dependencies etc. My understanding is that this file contains all the classes etc. compressed.
When we execute this jar file via the command line as follows java -jar myjar.jar , is this being decompressed on the fly? Does the interpreter first decompress everything before executing or how does this work exactly?
We already have one answer to similar question here :
How does a jar file get executed? Do the classes get extracted somewhere?
The JVM is capable of loading classes or files from a jar file without extracting the jar to temp files.This functionality is also available to you in the standard library, see the JarFile for more information.
So no, the JVM does not extract a jar to temp files, classes (and resources) are simply loaded on demand.
We can also check if the jar gets extracted or not by executing the command "java -jar myjar.jar" and check the folder where jar is located if there is any extraction while executing the program.
This question already has an answer here:
How do I compile a java file that has jar dependencies?
(1 answer)
Closed 8 years ago.
Background: Running on an ec2 instance not eclipse.
I have a java program that has external Jar dependencies. I want to create an executable jar file for this java program (being able to package the external jar files into this jar file would be icing on the cake)
The problem is that for me to use the java cf or cmf command I need to have a .class file. But, when I try javac HKP.java it throws a bunch of errors saying "xyz does not exist or cannot recognize symbol" which I'm guessing is because it has no idea about the external jar dependencies.
I have tried doing javac -sourcepath /home/ec2-user/apps/HKP/lib/ HKP.java, but it throws the exact same errors as before.
EDIT I have tried javac -classpath file1.jar, file2.jar, file3.jar HKP.java -I have also tried this with ";" in between. both return errors saying -bash file2.jar command not found, so instead of continuing the argument, bash is recognizing the multiple jar files as commands.This is the initial problem I had that caused me to post here.
Any help is much appreciated. Thank you!
If you want to compile a java source file into a class, you need to provide all classes which are used in that code on the classpath of the compiler.
If the classes come from (already compiled) external JARs, you typically do that by specifying javac -classpath with a list of JAR files, separated by : (on Linux). But you should really think about using an IDE or at least a maven build file (Which has the benefit, it can even download those JARs for you).
Both (Eclipse IDE and Maven build system) can also generate a ueber-jar with the external classes in there for easy execution.
try to Add the path in system variable and restart your computer.
This question already has answers here:
How do I find the packages defined in a jar?
(5 answers)
Closed 8 years ago.
Is there any way to know the packages of a .jar file as I want to use "gtranslateapi-1.0" but not getting the package or class names in it.
I have also added it to my libraries in netbeans 8.0
You can see it here: https://code.google.com/p/java-google-translate-text-to-speech/downloads/list
please help, thanks in advance !!
jar is just a zip.so if you want to know what is packed into a jar file, you may unzip it (using either your favourite zip tool or jar itself e.g jar -t to list the contents). hint jar without args gives you a list of options
in netbeans you can easily see packages and classes .or you can rename .jar to .zip and open in compress program like winrar
in netbeans you can expand jar easily.add jar to libries and expand it .this is your jar file
This question already has answers here:
How do I create an .exe for a Java program? [duplicate]
(7 answers)
Closed 9 years ago.
I have created a project in java Netbeans and I want to create an .exe or .jar file that can be run on any other systems.
my project have a Main.java class and an other class GetRules.java .
the .exe file should be such that it can be run in any folder that contain train.txt as input and create Model.txt as output
how can I do this?
what you are looking for is an executable file which can execute you project
calling you main class
so here is what you can do
step 1 : collect all the files , class files
step 2 : create a jar file collecting all the files from your project
step 3 : this.jar file is executable on any environment with a JVM available
you will have .jar file , rather than .exe file , but serves you the purpose
you can refer this link to learn how to create jar files
Java programs are not compiled into exe files but Java byte code which is usually stored in jar containers. exe files run on Windows systems only, but Java byte code is platform independent.
What you could do is use a wrapper like Launch4j. It wraps the jar file into an exe file.