You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by sairndain <sa...@yahoo.com> on 2008/08/19 04:35:13 UTC

including jars in a jar

(Please pardon for my weakness on Maven2 terminology)

What I want to do is create a java application jar that also includes other
"jar" files that are required in its application's classpath....


When I use the following plugin combination in my project pom...
i.e., 
-
-
-
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>1.5</source>
        <target>1.5</target>
    </configuration>
</plugin>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
    <archive>
        <index>true</index>
        <manifest>
            <addClasspath>true</addClasspath>
        </manifest>
    </archive>
    </configuration>
</plugin>
-
-
-

...the result contains classes, etc... But, not any of the supporting jars I
need to run this application from the command line:

test\META-INF
test\test
test\testws.wsdl
test\testws.xsd
test\META-INF\INDEX.LIST
test\META-INF\MANIFEST.MF
test\META-INF\maven
test\META-INF\maven\test.web.service
test\META-INF\maven\test.web.service\testwsClient
test\META-INF\maven\test.web.service\testwsClient\pom.properties
test\META-INF\maven\test.web.service\testwsClient\pom.xml
test\test\web
test\test\web\service
test\test\web\service\client
test\test\web\service\testws
test\test\web\service\client\TestwsClient.class
test\test\web\service\testws\ObjectFactory.class
test\test\web\service\testws\package-info.class
test\test\web\service\testws\RequestType.class
test\test\web\service\testws\ResponseType.class
test\test\web\service\testws\Testws.class
test\test\web\service\testws\TestwsOp.class
test\test\web\service\testws\TestwsOpResponse.class
test\test\web\service\testws\TestwsType.class
test\test\web\service\testws\Testws_Service.class


Ideally I'd like to have the dependent jars that are listed in the
application's manifest "classpath" included inside of the application's
jar...i.e. here is the manifest.mf --- note the jars in the classpath:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: dusty
Build-Jdk: 1.5.0_14
Class-Path: jaxws-rt-2.1.jar jaxws-api-2.1.jar jaxb-api-2.1.jar stax-a
 pi-1.0.jar activation-1.1.jar saaj-api-1.3.jar jsr250-api-1.0.jar jsr
 181-api-1.0-MR1.jar jaxb-impl-2.1.2.jar saaj-impl-1.3.jar streambuffe
 r-0.4.jar sjsxp-1.0.jar stax-ex-1.0.jar


If the application jar contains the "dependency" jars, then, I can run the
application from the command line...  something like this:
java -classpath ".;testwsClient.jar" test.web.service.client.TestwsClient

Any help appreciated!!!

P.S.

I've looked at some of the documentation on the "build-helper-maven-plugin".   

I'm not certain whether this is the plugin I want to use.   But, even if it
is, it is still not clear -- from the "pieces" of examples I've found --
where the plugin should be positioned in the pom....i.e., before the
maven-jar-plugin(?)...after(?)...  And it is not clear whether I would have
to explicitly list the dependent jars (listed in my manifest.mf classpath),
or whether the plugin can do this autmatically.

Are there any full sized "hello world" style poms that illustrate how to put
dependency jars inside of an application jar?
-- 
View this message in context: http://www.nabble.com/including-jars-in-a-jar-tp19043412p19043412.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: including jars in a jar

Posted by Wes Wannemacher <we...@wantii.com>.
Have you looked at jarjar ? 

http://code.google.com/p/jarjar/

Most of the docs show ANT usage, but I think you can use it in maven...

http://www.mvnrepository.com/artifact/com.tonicsystems/jarjar

Of course, I'd love to give you an example, but can't since I haven't
used it. Perhaps someone with experience using it can chime in?

-Wes

On Mon, 2008-08-18 at 19:35 -0700, sairndain wrote:
> (Please pardon for my weakness on Maven2 terminology)
> 
> What I want to do is create a java application jar that also includes other
> "jar" files that are required in its application's classpath....
> 
> 
> When I use the following plugin combination in my project pom...
> i.e., 
> -
> -
> -
> <plugin>
>     <groupId>org.apache.maven.plugins</groupId>
>     <artifactId>maven-compiler-plugin</artifactId>
>     <configuration>
>         <source>1.5</source>
>         <target>1.5</target>
>     </configuration>
> </plugin>
> 
> <plugin>
>     <groupId>org.apache.maven.plugins</groupId>
>     <artifactId>maven-jar-plugin</artifactId>
>     <configuration>
>     <archive>
>         <index>true</index>
>         <manifest>
>             <addClasspath>true</addClasspath>
>         </manifest>
>     </archive>
>     </configuration>
> </plugin>
> -
> -
> -
> 
> ...the result contains classes, etc... But, not any of the supporting jars I
> need to run this application from the command line:
> 
> test\META-INF
> test\test
> test\testws.wsdl
> test\testws.xsd
> test\META-INF\INDEX.LIST
> test\META-INF\MANIFEST.MF
> test\META-INF\maven
> test\META-INF\maven\test.web.service
> test\META-INF\maven\test.web.service\testwsClient
> test\META-INF\maven\test.web.service\testwsClient\pom.properties
> test\META-INF\maven\test.web.service\testwsClient\pom.xml
> test\test\web
> test\test\web\service
> test\test\web\service\client
> test\test\web\service\testws
> test\test\web\service\client\TestwsClient.class
> test\test\web\service\testws\ObjectFactory.class
> test\test\web\service\testws\package-info.class
> test\test\web\service\testws\RequestType.class
> test\test\web\service\testws\ResponseType.class
> test\test\web\service\testws\Testws.class
> test\test\web\service\testws\TestwsOp.class
> test\test\web\service\testws\TestwsOpResponse.class
> test\test\web\service\testws\TestwsType.class
> test\test\web\service\testws\Testws_Service.class
> 
> 
> Ideally I'd like to have the dependent jars that are listed in the
> application's manifest "classpath" included inside of the application's
> jar...i.e. here is the manifest.mf --- note the jars in the classpath:
> 
> Manifest-Version: 1.0
> Archiver-Version: Plexus Archiver
> Created-By: Apache Maven
> Built-By: dusty
> Build-Jdk: 1.5.0_14
> Class-Path: jaxws-rt-2.1.jar jaxws-api-2.1.jar jaxb-api-2.1.jar stax-a
>  pi-1.0.jar activation-1.1.jar saaj-api-1.3.jar jsr250-api-1.0.jar jsr
>  181-api-1.0-MR1.jar jaxb-impl-2.1.2.jar saaj-impl-1.3.jar streambuffe
>  r-0.4.jar sjsxp-1.0.jar stax-ex-1.0.jar
> 
> 
> If the application jar contains the "dependency" jars, then, I can run the
> application from the command line...  something like this:
> java -classpath ".;testwsClient.jar" test.web.service.client.TestwsClient
> 
> Any help appreciated!!!
> 
> P.S.
> 
> I've looked at some of the documentation on the "build-helper-maven-plugin".   
> 
> I'm not certain whether this is the plugin I want to use.   But, even if it
> is, it is still not clear -- from the "pieces" of examples I've found --
> where the plugin should be positioned in the pom....i.e., before the
> maven-jar-plugin(?)...after(?)...  And it is not clear whether I would have
> to explicitly list the dependent jars (listed in my manifest.mf classpath),
> or whether the plugin can do this autmatically.
> 
> Are there any full sized "hello world" style poms that illustrate how to put
> dependency jars inside of an application jar?


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: good tutorial for maven, eclipse3.4 and tomcat

Posted by Peter Horlock <pe...@googlemail.com>.
P.s.: I guess the reason you want such a "book that has it all", is because
you are looking for "the fast way".
There is nothing like that. Learning is a process, and this process ALWAYS
takes it's time.
Please - take your time. Seriously read one good book for each topic - and
only then you (might) know enough to build a proper something...

If you want it the fast way, you will understand some basic concepts, and
this leeds to crap that more experienced programmers will have to fix
someday for you, and then this (reverse engineering, refactoring...) will
take even MUCH more time

So pleeease, TAKE YOUR TIME, study new topics properly!

Re: good tutorial for maven, eclipse3.4 and tomcat

Posted by Peter Horlock <pe...@googlemail.com>.
2008/8/19 sam wun <sw...@gmx.com>

> Can anyone provide me a link of tutorial  that I can follow to build a
> simple web base application using maven, eclipse 3.4, tomcat and mysql?
>
>
Maven:
http://www.sonatype.com/community/definitive_guide.html

For all other topics, I can't help you, I would buy a good book (for EACH
topic)
Don't go for "the one that has it all" - they often say a lot, yet imho it's
always better to
have "specialists" - I would also never buy a "printer foto copy scanner (+
coffee machine and fridge...)".

good tutorial for maven, eclipse3.4 and tomcat

Posted by sam wun <sw...@gmx.com>.
Hi,



Can anyone provide me a link of tutorial  that I can follow to build a 
simple web base application using maven, eclipse 3.4, tomcat and mysql?



Thanks



Re: including jars in a jar

Posted by sairndain <sa...@yahoo.com>.
Hi Nick

Thanks for the input.  

I've tried the "Maven Assembly Plugin" and some else has suggested the
"maven-shade-plugin".

Both, pretty much, do the job...But, the "maven-shade-plugin" names the
artifact the way I want.

I will post the entire pom, below, so that new comers to Maven2 -- like
myself -- can get a better context of how these plugins fit into my pom:


<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>test.web.service</groupId>
  <artifactId>testwsClient</artifactId>
  <packaging>jar</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>testwsClient</name>
  <url>http://maven.apache.org</url>
  <repositories>
    <repository>
      <id>maven-repository.dev.java.net</id>
      <name>Java.net Repository for Maven 1</name>
      <url>http://download.java.net/maven/1/</url>
      <layout>legacy</layout>
    </repository>
    <repository>
      <id>maven2-repository.dev.java.net</id>
      <name>Java.net Repository for Maven 2</name>
      <url>http://download.java.net/maven/2/</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <id>maven2-repository.dev.java.net</id>
      <name>Java.net Repository for Maven</name>
      <url>http://download.java.net/maven/2/</url>
      <layout>default</layout>
    </pluginRepository>
  </pluginRepositories>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.sun.xml.ws</groupId>
      <artifactId>jaxws-rt</artifactId>
      <version>2.1</version>
    </dependency>
    <dependency>
      <groupId>com.sun.xml.ws</groupId>
      <artifactId>resolver</artifactId>
      <version>2.1</version>
    </dependency>
    <dependency>
      <groupId>was61</groupId>
      <artifactId>ws_runtime</artifactId>
      <version>6.1.0</version>
      <scope>system</scope>
     
<systemPath>C:/opt/IBM/WebSphere/AppServer/deploytool/itp/plugins/com.ibm.websphere.v61_6.1.200/ws_runtime.jar</systemPath>
    </dependency>
    <dependency>
      <groupId>was61</groupId>
      <artifactId>ws_runtime</artifactId>
      <version>6.1.0</version>
      <scope>system</scope>
      <systemPath> C:/opt/IBM/WebSphere/AppServer/lib/j2ee.jar</systemPath>
    </dependency>
    <dependency>
      <groupId>was61</groupId>
      <artifactId>com.ibm.jaxws.thinclient 
      </artifactId>
      <version>6.1.0</version>
      <scope>system</scope>
     
<systemPath>C:/opt/IBM/WebSphere/AppServer/runtimes/com.ibm.jaxws.thinclient_6.1.0.jar</systemPath>
    </dependency>
  </dependencies>
  <build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jaxws-maven-plugin</artifactId>
        <executions>
          <execution>
            <phase>generate-sources</phase>
            <goals>
              <goal>wsimport</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <packageName>test.web.service.testws 
          </packageName>
          <wsdlDirectory>
            C:/EGworkspace3/testws/testws-war/src/main/resources 
          </wsdlDirectory>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>
      
      
      <!-- this produces: "testwsClient-0.0.1-SNAPSHOT.jar", you can run
from the windows command line like:
        cd c:/EGworkspace4/testwsClient/target
        java -classpath ".;testwsClient-0.0.1-SNAPSHOT.jar"
test.web.service.client.TestwsClient
      -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <transformers>
                <transformer
                 
implementation="org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer"
/>
              </transformers>
            </configuration>
          </execution>
        </executions>
      </plugin>
      
      
      <!--  this produces:  "testwsClient-jar-with-dependencies.jar", you
can run from the command line like:
        cd c:/EGworkspace4/testwsClient/target 
        java -classpath ".;testwsClient-jar-with-dependencies.jar"
test.web.service.client.TestwsClient

        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <configuration>
            <descriptorRefs>
              <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
          </configuration>
          <executions>
            <execution>
              <id>make-assembly</id>
              <phase>package</phase>
              <goals>
                <goal>attached</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
      -->
      
      
    </plugins>
  </build>
</project>








Nick Stolwijk-4 wrote:
> 
> Hi,
> 
> Take a look at the Maven Assembly Plugin [1], especially its unpack goal
> [2]
> in combination with the predefined descriptor "jar-with-dependencies" [3].
> I
> think this does exactly what you want.
> 
> Hth,
> 
> [1] http://maven.apache.org/plugins/maven-assembly-plugin/
> [2] http://maven.apache.org/plugins/maven-assembly-plugin/unpack-mojo.html
> [3]
> http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html#jar-with-dependencies
> 
> Nick Stolwijk
> ~Java Developer~
> 
> Iprofs BV.
> Claus Sluterweg 125
> 2012 WS Haarlem
> www.iprofs.nl
> 
> 
> On Tue, Aug 19, 2008 at 5:57 AM, Wayne Fay <wa...@gmail.com> wrote:
> 
>> On 8/18/08, sairndain <sa...@yahoo.com> wrote:
>> >
>> > What I want to do is create a java application jar that also includes
>> other
>> > "jar" files that are required in its application's classpath....
>>
>> You realize that "jars inside a jar" is not supported by the default
>> Sun JVM classloader, right?
>>
>> This is a packaging approach supported by EARs and WARs, but not JARs
>> unless you are running a specialized classloader.
>>
>> You can also unzip the various dependency jars (into /target) and
>> include them in your jar, which would give you a single (large) jar
>> file that can execute your app. The dependency plugin can help with
>> this and/or assembly plugin.
>>
>> Wayne
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/including-jars-in-a-jar-tp19043412p19049257.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: including jars in a jar

Posted by Nick Stolwijk <ni...@gmail.com>.
Hi,

Take a look at the Maven Assembly Plugin [1], especially its unpack goal [2]
in combination with the predefined descriptor "jar-with-dependencies" [3]. I
think this does exactly what you want.

Hth,

[1] http://maven.apache.org/plugins/maven-assembly-plugin/
[2] http://maven.apache.org/plugins/maven-assembly-plugin/unpack-mojo.html
[3]
http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html#jar-with-dependencies

Nick Stolwijk
~Java Developer~

Iprofs BV.
Claus Sluterweg 125
2012 WS Haarlem
www.iprofs.nl


On Tue, Aug 19, 2008 at 5:57 AM, Wayne Fay <wa...@gmail.com> wrote:

> On 8/18/08, sairndain <sa...@yahoo.com> wrote:
> >
> > What I want to do is create a java application jar that also includes
> other
> > "jar" files that are required in its application's classpath....
>
> You realize that "jars inside a jar" is not supported by the default
> Sun JVM classloader, right?
>
> This is a packaging approach supported by EARs and WARs, but not JARs
> unless you are running a specialized classloader.
>
> You can also unzip the various dependency jars (into /target) and
> include them in your jar, which would give you a single (large) jar
> file that can execute your app. The dependency plugin can help with
> this and/or assembly plugin.
>
> Wayne
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: including jars in a jar

Posted by Wayne Fay <wa...@gmail.com>.
On 8/18/08, sairndain <sa...@yahoo.com> wrote:
>
> What I want to do is create a java application jar that also includes other
> "jar" files that are required in its application's classpath....

You realize that "jars inside a jar" is not supported by the default
Sun JVM classloader, right?

This is a packaging approach supported by EARs and WARs, but not JARs
unless you are running a specialized classloader.

You can also unzip the various dependency jars (into /target) and
include them in your jar, which would give you a single (large) jar
file that can execute your app. The dependency plugin can help with
this and/or assembly plugin.

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org