I'm trying to submit my java homework,and would like to create a jar file that contains the compiled .class files as well as my original source code .java files. I'm using IntelliJ, but didn't find an option of exporting .java to jar. Is there a way to do it by commandlines?
4 Answers
try
jar cf jar-file input-file(s)
check http://docs.oracle.com/javase/tutorial/deployment/jar/build.html for more info
Comments
Creating a jar file using IntelliJ
For Intellij IDEA version 11.0.2
File | Project Structure | Artifacts then you should press alt+insert or click the plus icon and create new artifact choose --> jar --> From modules with dependencies.
Next goto Build | Build artifacts --> choose your artifact.
Refer this link create-jar-with-IntelliJ
Creating a jar File in Command Prompt
- Start Command Prompt.
- Navigate to the folder that holds your class files:
C:\>cd \mywork
- Set path to include JDK’s bin. For example:
C:\mywork> path c:\Program Files\Java\jdk1.7.0_25\bin;%path%
- Compile your class(es):
C:\mywork> javac *.java
- Create a manifest file
manifest.txt with, for example, this content:
Manifest-Version: 1.0
Created-By: 1.8.0_171 (Oracle Corporation) #your jdk version
Main-Class: mainPackage.MainClass
- Create the jar file:
C:\mywork> jar cvfm Craps.jar manifest.txt *.class
Comments
In Eclipse Help contents, expand "Java development user guide" ==> "Tasks" ==> "Creating JAR files." Follow the instructions for "Creating a new JAR file" or "Creating a new runnable JAR file."
The JAR File and Runnable JAR File commands are for some reason located under the File menu: click on Export... and expand the Java node.
Refer this: http://docs.oracle.com/javase/tutorial/deployment/jar/build.html
Comments
You can achieve through command line, but i suggest you to go for build script, which is professional way of doing so.
Try Ant Script to achieve your requirement.
Tutorial link for Ant - http://www.tutorialspoint.com/ant/ant_creating_jar_files.htm