0

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

GurdeepS
  • 65,107
  • 109
  • 251
  • 387

3 Answers3

1

Here is a link to the tutorial that might help.

Faisal Feroz
  • 12,458
  • 4
  • 40
  • 51
1

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.

Community
  • 1
  • 1
Alfred
  • 60,935
  • 33
  • 147
  • 186
0

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.

Vincent Ramdhanie
  • 102,349
  • 23
  • 137
  • 192
  • Thanks. I think I know why it doesn't work, that is because there are no java-related env variables on my Windows system. What env variables do I need? – GurdeepS Jan 15 '11 at 12:29
  • You need to add the location where java's jdk is installed to the path variable at least. I don't think anything else is required. – Vincent Ramdhanie Jan 15 '11 at 13:13