GurdeepS
GurdeepS

Reputation: 67273

Jar'ing Java project, and not one class

I want to create a jar file of a Java project, which compiles. I've looked on the internet but all the examples of how to do this seem to take one java file and work on that. I want to jar the root of the java project. How is this possible?

Thanks

Upvotes: 0

Views: 266

Answers (3)

Alfred
Alfred

Reputation: 61793

IntelliJ

According to this Stackoverflow topic you can built jar file using

You didn't specify your IDEA version. Before 9.0 use Build | Build Jars, in IDEA 9.0 use Project Structure | Artifacts.

Maven

You should learn to use a build tool like maven. You then could use the maven assembly plugin

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-assembly-plugin</artifactId>
     <executions>
       <execution>
         <goals>
           <goal>attached</goal>
         </goals>
         <phase>package</phase>
         <configuration>
           <descriptorRefs>
             <descriptorRef>jar-with-dependencies</descriptorRef>
           </descriptorRefs>
           <archive>
             <manifest>
               <mainClass>*******your main class******</mainClass>
             </manifest>
           </archive>
         </configuration>
       </execution>
     </executions>
</plugin>

Ant

Or you could use ant(2) to create a jar file.

Upvotes: 1

Faisal Feroz
Faisal Feroz

Reputation: 12785

Here is a link to the tutorial that might help.

Upvotes: 1

Vincent Ramdhanie
Vincent Ramdhanie

Reputation: 103145

The jar command takes either files or directories. So you can simply specify the name of the directory that you want to jar rather than a file name. Once you know the command to jar a single file then you can jar a directory. More details here.

And this tutorial shows an example of jaring a file and a number of directories together.

Upvotes: 0

Related Questions