Creating a JAR with dependencies

View: New views
5 Messages — Rating Filter:   Alert me  

Creating a JAR with dependencies

by maven_newbie99 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,

I'm a Maven Newbie, so please forgive me if you find my question stupid.

In my project I use libraries such as Apache commons-collections and many more. When I create an executable .JAR file of my project using the
org.apache.maven.plugins:maven-jar-plugin:2.2:jar
Goal, which I configured like this:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <configuration>
    <archive>
      <manifest>
        <addClasspath>true</addClasspath>
        <mainClass>path.to.my.MainClass</mainClass>
      </manifest>
    </archive>
  </configuration>
</plugin>

It creates a .JAR file in the target folder containing only the source of my project. Additionally it creates a subfolder "dependencies" containing all dependent JARs.
What I really want is
first: the sources and the dependencies should be contained in a single JAR
second: is it possible not to include the whole dependent JARs but only those classes within my dependencies that I really use in my code? Because now my dependencies folder is about 11MB large, however I use only a tiny portion of my dependencies.

Thanks a lot for any help!




Re: Creating a JAR with dependencies

by Jesse Farinacci :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Frank,

On Wed, Nov 4, 2009 at 7:09 AM, maven_newbie99 <frank@...> wrote:
>
> second: is it possible not to include the whole dependent JARs but only
> those classes within my dependencies that I really use in my code?

Try http://mojo.codehaus.org/minijar-maven-plugin/

--
There are 10 types of people in this world, those
that can read binary and those that can not.

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


Re: Creating a JAR with dependencies

by maven_newbie99 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi jieryn,

I could achieve what I want using your link (ueberjar). Many thanks.

The only thing I don't understand is why so many maven-specific libraries are included in my taret? For eample:
mavenmodel, mavenmonitor, mavenpluginapi, mavenpluginregistry, ...
plexusarchiver, plexuscontainerdefault, ...
junit

and many more. It's a total of 77 libraries of which only ~10 are really used in my project.

What do I need to change in order to get rid of these libraries in the target?

I appreciate any help.

Frank


jieryn wrote:
Hi Frank,

On Wed, Nov 4, 2009 at 7:09 AM, maven_newbie99 <frank@visign.ch> wrote:
>
> second: is it possible not to include the whole dependent JARs but only
> those classes within my dependencies that I really use in my code?

Try http://mojo.codehaus.org/minijar-maven-plugin/

--
There are 10 types of people in this world, those
that can read binary and those that can not.

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

Re: Creating a JAR with dependencies

by maven_newbie99 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Please forget about my last post.

I have had, for some copy/paste reason, the following lines in my .pom:
<dependency>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <version>2.1</version>
</dependency>

which caused all these maven-specific libs to be added to the target.

Sorry.

Best regards, Frank



Hi jieryn,

I could achieve what I want using your link (ueberjar). Many thanks.

The only thing I don't understand is why so many maven-specific libraries are included in my taret? For eample:
mavenmodel, mavenmonitor, mavenpluginapi, mavenpluginregistry, ...
plexusarchiver, plexuscontainerdefault, ...
junit

and many more. It's a total of 77 libraries of which only ~10 are really used in my project.

What do I need to change in order to get rid of these libraries in the target?

I appreciate any help.

Frank


jieryn wrote:
Hi Frank,

On Wed, Nov 4, 2009 at 7:09 AM, maven_newbie99 <frank@visign.ch> wrote:
>
> second: is it possible not to include the whole dependent JARs but only
> those classes within my dependencies that I really use in my code?

Try http://mojo.codehaus.org/minijar-maven-plugin/

--
There are 10 types of people in this world, those
that can read binary and those that can not.

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


Re: Creating a JAR with dependencies

by Jesse Farinacci :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

A-ha! Ok, glad to hear you figured it out. :-)

On Wed, Nov 4, 2009 at 9:30 AM, maven_newbie99 <frank@...> wrote:

>
> Please forget about my last post.
>
> I have had, for some copy/paste reason, the following lines in my .pom:
> <dependency>
>  <groupId>org.apache.maven.plugins</groupId>
>  <artifactId>maven-dependency-plugin</artifactId>
>  <version>2.1</version>
> </dependency>
>
> which caused all these maven-specific libs to be added to the target.
>

-Jesse

--
There are 10 types of people in this world, those
that can read binary and those that can not.

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