11

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?

1
  • What is your IntelliJ version ? Commented Oct 29, 2013 at 6:17

4 Answers 4

10

try

jar cf jar-file input-file(s)

check http://docs.oracle.com/javase/tutorial/deployment/jar/build.html for more info

Sign up to request clarification or add additional context in comments.

Comments

8

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

1

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

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.