ict1991
ict1991

Reputation: 2110

how to place all jar files in one jar file?

is it possible to build a jar file made up of all jar files that I need? I am building my project and the jar files are not being included in the generated jar file and I would like to generate one separate jar file which contains all jar files in this project

Upvotes: 1

Views: 3150

Answers (5)

Gesuino
Gesuino

Reputation: 26

You can use one jar maven plug in.

<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
    <!--                   REPOSITORIES                          -->
    <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

    <pluginRepositories>
        <pluginRepository>
            <id>onejar-maven-plugin.googlecode.com</id>
            <url>http://onejar-maven-plugin.googlecode.com/svn/mavenrepo</url>
        </pluginRepository>
    </pluginRepositories>
    <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
            <!--                      ONE JAR PLUGIN                     -->
            <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>org.acme.MainClass</mainClass>
                            </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.dstovall</groupId>
                <artifactId>onejar-maven-plugin</artifactId>
                <version>1.4.4</version>
                <executions>
                    <execution>
                        <configuration>
                            <!-- Optional -->
                            <onejarVersion>0.97</onejarVersion>
                            <!--
                                Optional, use only if you need to include native libraries
                                (dll's) <binlibs> <fileSet>
                                <directory>${project.build.directory}/dllextract</directory>
                                <includes> <include>test.dll</include> </includes> </fileSet>
                                </binlibs>
                            -->
                            <!-- Optional, default is false -->
                            <attachToBuild>true</attachToBuild>
                            <!-- Optional, default is "onejar" -->
                            <classifier>onejar</classifier>
                        </configuration>
                        <goals>
                            <goal>one-jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

Upvotes: 0

Bozho
Bozho

Reputation: 597362

Not possible. You can't include jars in a jar in order to have them on the classpath (you can put them in the jar, but you can't use them as dependencies)

Maven, however, gives you an alternative with the maven-assembly-plugin. It unpacks all jars and stores their .class files in your new, single jar. There are, of course, other options to do the same thing, but maven is a great build tool to use anyway.

Upvotes: 0

evanwong
evanwong

Reputation: 5134

Take a look at onejar: http://one-jar.sourceforge.net/

Upvotes: 0

Sarel Botha
Sarel Botha

Reputation: 12710

The yguard tool can do this. It can also shrink your code and obfuscate it if you wish.

Here is an ant example from their documentation:

  <taskdef name="yguard" classname="com.yworks.yguard.YGuardTask" classpath="buildlib/yguard.jar"/>

  <inoutpairs resources="auto">
    <fileset dir="${input-lib-dir}">
      <include name="myapp*.jar"/>
      <exclude name="*_obf.jar"/>
    </fileset>
    <mapper type="glob" from="*.jar" to="*_obf.jar"/>
  </inoutpairs>

Upvotes: 0

Andrejs
Andrejs

Reputation: 27737

There are Eclipse plugins that can do that FatJar, JarsSplice

Upvotes: 3

Related Questions