0

I am involved in creating a project which has around 60 packages and more than 150 classes and also some external libraries. How can i package these things in to a single executable jar file, so that i can run it as an application. can anyone please provide the detailed steps.

Thanks to the replier in advance.

Sakthi.droid
  • 187
  • 1
  • 1
  • 10
  • 1
    Does anyone even search anymore before posting questions? This has been asked many, many times on SO. Possible duplicate of [Executable Jar with depedencies](http://stackoverflow.com/questions/3753894/executable-jar-with-depedencies) – Perception Feb 03 '12 at 15:07
  • This one is possibly more relevant: [deploying all in one jar](http://stackoverflow.com/questions/2212913/netbeans-deploying-all-in-one-jar). – Dmitri Feb 03 '12 at 15:58

4 Answers4

1

In Eclipse choose 'Export as Runnable JAR'.

If you want it all in one file, choose 'extract libraries into JAR'.

Garrett Hall
  • 29,524
  • 10
  • 61
  • 76
  • Thanks Garrett, Now I am able to generate an executable jar file and it works fine too. but i have one issue. it is working only when placed in the project's workspace and not outside of it. Any ideas would be really greatful. – Sakthi.droid Feb 07 '12 at 13:03
  • Do you have any failure messages? You can try setting the [classpath when running the JAR](http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html) and see if that fixes it. In that case, you have dependencies in your workspace that are not in the JAR. – Garrett Hall Feb 07 '12 at 14:13
0

I would strongly recommend you to mavenize it. Using Apache Maven will help you a lot in the long run with the project describe.

Kris
  • 5,714
  • 2
  • 27
  • 47
0

If you are using Netbeans, right-click on your project, click on Clean and Build. This will create a folder named dist in your project's root directory. That folder contains the jar file.

Sunil Kumar B M
  • 2,735
  • 1
  • 24
  • 31
0

You can use maven to build your project and generate a jar with all of the dependencies with maven-shade-plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>1.4</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <finalName>my-executable</finalName>
        <shadedArtifactAttached>true</shadedArtifactAttached>
        <shadedClassifierName>shaded</shadedClassifierName>
        <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                <!-- Main class -->
                <mainClass>com.worklight.my.cli.MainClassName
                </mainClass>
            </transformer>
        </transformers>
    </configuration>
</plugin>
Enrico
  • 621
  • 1
  • 4
  • 12