You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Jorge Infante Osorio <jo...@uci.cu> on 2013/06/12 05:35:27 UTC

Include maven dependencies inside jar file

Hi all.

I´m newbie in maven.

I have a Maven project and I need to build a jar file with the maven
dependencies inside, like I do with export jar as runnable in Eclipse to
execute the functionality from the command line.

What plugin can I use for this with what config?

Thanks.

Saludos,
Ing. Jorge Infante Osorio.
CDAE.
Fac. 5.
UCI.
“En un mundo perfecto las pizzas serían una comida saludable, las laptops se
cargarían desde una fuente de corriente inalámbrica y todos los JAR serían
bundles de OSGI ”


http://www.uci.cu

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


Re: Include maven dependencies inside jar file

Posted by Baptiste MATHUS <ml...@batmat.net>.
Hi,
As you already saw, there's a special classloader to handle embedding jars
into jars (which is in fact not standard).

There is (was?) a maven plugin called onejar-maven-plugin that would do
exactly that. This is a variant (currently offline so I can't double-check)
of the fatjar-maven-plugin.

Cheers
Le 13 juin 2013 05:51, "Kevin Krumwiede" <kj...@gmail.com> a écrit :

> Oh, I forgot to mention: I set up my pom so the classpath of my main
> jar includes lib/, so all my users have to do is unzip it and run the
> main jar.
>
> On 6/12/13, Kevin Krumwiede <kj...@gmail.com> wrote:
> > As Anders Hammar said, there is some classpath magic to the way
> > Eclipse creates executable jars containing other jars.  I wanted
> > something like that, but instead I ended up creating an assembly that
> > creates a zip file.  The zip file contains my main executable jar,
> > along with all the dependencies in a lib/ directory.  Because I wanted
> > the zip file to contain an artifact from a project that depends on my
> > main jar, I had to separate the assembly pom from my main pom.  Now I
> > build my main project, build the artifact that depends on it, and then
> > build the assembly.
> >
> > My files are here:
> http://sourceforge.net/p/weapon-m/svn/HEAD/tree/trunk/
> >
> > On 6/12/13, Wayne Fay <wa...@gmail.com> wrote:
> >>> Wayne, I do the check and yes the dependency is inside the exec jar and
> >>> yes inside that dependency I found the class AxisFault.class.
> >>
> >> In that case, I cannot explain the error you seem to have run into.
> >>
> >> Wayne
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> >> For additional commands, e-mail: users-help@maven.apache.org
> >>
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: Include maven dependencies inside jar file

Posted by Kevin Krumwiede <kj...@gmail.com>.
Oh, I forgot to mention: I set up my pom so the classpath of my main
jar includes lib/, so all my users have to do is unzip it and run the
main jar.

On 6/12/13, Kevin Krumwiede <kj...@gmail.com> wrote:
> As Anders Hammar said, there is some classpath magic to the way
> Eclipse creates executable jars containing other jars.  I wanted
> something like that, but instead I ended up creating an assembly that
> creates a zip file.  The zip file contains my main executable jar,
> along with all the dependencies in a lib/ directory.  Because I wanted
> the zip file to contain an artifact from a project that depends on my
> main jar, I had to separate the assembly pom from my main pom.  Now I
> build my main project, build the artifact that depends on it, and then
> build the assembly.
>
> My files are here: http://sourceforge.net/p/weapon-m/svn/HEAD/tree/trunk/
>
> On 6/12/13, Wayne Fay <wa...@gmail.com> wrote:
>>> Wayne, I do the check and yes the dependency is inside the exec jar and
>>> yes inside that dependency I found the class AxisFault.class.
>>
>> In that case, I cannot explain the error you seem to have run into.
>>
>> Wayne
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
>

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


Re: Include maven dependencies inside jar file

Posted by Kevin Krumwiede <kj...@gmail.com>.
As Anders Hammar said, there is some classpath magic to the way
Eclipse creates executable jars containing other jars.  I wanted
something like that, but instead I ended up creating an assembly that
creates a zip file.  The zip file contains my main executable jar,
along with all the dependencies in a lib/ directory.  Because I wanted
the zip file to contain an artifact from a project that depends on my
main jar, I had to separate the assembly pom from my main pom.  Now I
build my main project, build the artifact that depends on it, and then
build the assembly.

My files are here: http://sourceforge.net/p/weapon-m/svn/HEAD/tree/trunk/

On 6/12/13, Wayne Fay <wa...@gmail.com> wrote:
>> Wayne, I do the check and yes the dependency is inside the exec jar and
>> yes inside that dependency I found the class AxisFault.class.
>
> In that case, I cannot explain the error you seem to have run into.
>
> Wayne
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

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


Re: Include maven dependencies inside jar file

Posted by Wayne Fay <wa...@gmail.com>.
> Wayne, I do the check and yes the dependency is inside the exec jar and
> yes inside that dependency I found the class AxisFault.class.

In that case, I cannot explain the error you seem to have run into.

Wayne

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


Re: Include maven dependencies inside jar file

Posted by Anders Hammar <an...@hammar.net>.
IIRC, there is no Java standard to put dependency JARs in a jar file. So I
believe there is some Eclipse magic (hence that file) to get that rolling.

/Anders


On Wed, Jun 12, 2013 at 9:59 PM, Jorge Infante Osorio <jo...@uci.cu>wrote:

> Wayne, I do the check and yes the dependency is inside the exec jar and
> yes inside that dependency I found the class AxisFault.class.
>
> When I ask about a class loader and put the eclipse example it´s because I
> see this difference when compare the two jar, one generate by eclipse and
> the another by maven.
>
> Saludos,
> Ing. Jorge Infante Osorio.
> CDAE.
> Fac. 5.
> UCI.
> “En un mundo perfecto las pizzas serían una comida saludable, las laptops
> se cargarían desde una fuente de corriente inalámbrica y todos los JAR
> serían bundles de OSGI ”
>
>
> -----Mensaje original-----
> De: Wayne Fay [mailto:waynefay@gmail.com]
> Enviado el: miércoles, 12 de junio de 2013 14:32
> Para: Maven Users List
> Asunto: Re: Include maven dependencies inside jar file
>
> > I double check and maven include this dependency inside the exec jar:
> > axis2-1.6.1.wso2v6.jar and this dependency have
> > org\apache\axis2\AxisFault.class
>
> Unzip your jar file (or just drill into it) and see if that
> AxisFault.class file is inside the jar you created.
>
> > I could be a problem with the class loader? Eclipse include this package
> inside the exec jar:
> > org\eclipse\jdt\internal\jarinjarloader
>
> I really have no idea how Eclipse creates executable jars, nor any special
> interest in it. I'm here to talk about Maven.
>
> Wayne
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
> http://www.uci.cu
>
> http://www.uci.cu
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

RE: Include maven dependencies inside jar file

Posted by Jorge Infante Osorio <jo...@uci.cu>.
Wayne, I do the check and yes the dependency is inside the exec jar and yes inside that dependency I found the class AxisFault.class.

When I ask about a class loader and put the eclipse example it´s because I see this difference when compare the two jar, one generate by eclipse and the another by maven.

Saludos,
Ing. Jorge Infante Osorio.
CDAE.
Fac. 5.
UCI.
“En un mundo perfecto las pizzas serían una comida saludable, las laptops se cargarían desde una fuente de corriente inalámbrica y todos los JAR serían bundles de OSGI ”


-----Mensaje original-----
De: Wayne Fay [mailto:waynefay@gmail.com] 
Enviado el: miércoles, 12 de junio de 2013 14:32
Para: Maven Users List
Asunto: Re: Include maven dependencies inside jar file

> I double check and maven include this dependency inside the exec jar: 
> axis2-1.6.1.wso2v6.jar and this dependency have 
> org\apache\axis2\AxisFault.class

Unzip your jar file (or just drill into it) and see if that AxisFault.class file is inside the jar you created.

> I could be a problem with the class loader? Eclipse include this package inside the exec jar:
> org\eclipse\jdt\internal\jarinjarloader

I really have no idea how Eclipse creates executable jars, nor any special interest in it. I'm here to talk about Maven.

Wayne

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

http://www.uci.cu

http://www.uci.cu

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


Re: Include maven dependencies inside jar file

Posted by Wayne Fay <wa...@gmail.com>.
> I double check and maven include this dependency inside the exec jar: axis2-1.6.1.wso2v6.jar
> and this dependency have org\apache\axis2\AxisFault.class

Unzip your jar file (or just drill into it) and see if that
AxisFault.class file is inside the jar you created.

> I could be a problem with the class loader? Eclipse include this package inside the exec jar:
> org\eclipse\jdt\internal\jarinjarloader

I really have no idea how Eclipse creates executable jars, nor any
special interest in it. I'm here to talk about Maven.

Wayne

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


RE: Include maven dependencies inside jar file

Posted by Jorge Infante Osorio <jo...@uci.cu>.
I have two jar, one created with eclipse and another with maven. Both have the same dependencies but the one with maven have this error:

> Exception in thread "main" java.lang.NoClassDefFoundError:
> org/apache/axis2/AxisFault

I double check and maven include this dependency inside the exec jar: axis2-1.6.1.wso2v6.jar and this dependency have org\apache\axis2\AxisFault.class

I could be a problem with the class loader? Eclipse include this package inside the exec jar: org\eclipse\jdt\internal\jarinjarloader 

Saludos,
Ing. Jorge Infante Osorio.
CDAE.
Fac. 5.
UCI.
“En un mundo perfecto las pizzas serían una comida saludable, las laptops se cargarían desde una fuente de corriente inalámbrica y todos los JAR serían bundles de OSGI ”


-----Mensaje original-----
De: Wayne Fay [mailto:waynefay@gmail.com] 
Enviado el: miércoles, 12 de junio de 2013 13:50
Para: Maven Users List
Asunto: Re: Include maven dependencies inside jar file

> Now I see all the dependencies include inside my execute jar like 
> Eclipse do it, but when I try it I see this error:
>
> Exception in thread "main" java.lang.NoClassDefFoundError:
> org/apache/axis2/AxisFault

It seems you are missing a necessary dependency, thus the NoClassDefFoundError you ran into. Looks like you need to add a dependency to Axis2.

Wayne

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

http://www.uci.cu

http://www.uci.cu

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


Re: Include maven dependencies inside jar file

Posted by Wayne Fay <wa...@gmail.com>.
> Now I see all the dependencies include inside my execute jar like Eclipse do
> it, but when I try it I see this error:
>
> Exception in thread "main" java.lang.NoClassDefFoundError:
> org/apache/axis2/AxisFault

It seems you are missing a necessary dependency, thus the
NoClassDefFoundError you ran into. Looks like you need to add a
dependency to Axis2.

Wayne

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


RE: Include maven dependencies inside jar file

Posted by Jorge Infante Osorio <jo...@uci.cu>.
Hi Anders.

I put this inside my pom.xml


<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
 
<outputDirectory>${project.build.directory}/classes</outputDirectory>
                        <overWriteReleases>false</overWriteReleases>
                        <overWriteSnapshots>false</overWriteSnapshots>
                        <overWriteIfNewer>true</overWriteIfNewer>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <!--classpathPrefix></classpathPrefix-->
                        <mainClass>test.org.Cliente</mainClass>
                    </manifest>
            <manifestEntries>
                <Class-Path>/</Class-Path>
            </manifestEntries>					
                </archive>
            </configuration>
        </plugin>		

Now I see all the dependencies include inside my execute jar like Eclipse do
it, but when I try it I see this error:

Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/axis2/AxisFault
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
        at java.lang.Class.getMethod0(Unknown Source)
        at java.lang.Class.getMethod(Unknown Source)
        at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.axis2.AxisFault
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 6 more


Any idea?

Saludos,
Ing. Jorge Infante Osorio.
CDAE.
Fac. 5.
UCI.
“En un mundo perfecto las pizzas serían una comida saludable, las laptops se
cargarían desde una fuente de corriente inalámbrica y todos los JAR serían
bundles de OSGI ”

-----Mensaje original-----
De: anders.g.hammar@gmail.com [mailto:anders.g.hammar@gmail.com] En nombre
de Anders Hammar
Enviado el: miércoles, 12 de junio de 2013 1:51
Para: Maven Users List
Asunto: Re: Include maven dependencies inside jar file

If you want the deps extracted, you need to do a combination of [1] and [2].

If you want the dep jars included in the final jar, I think you best option
is to use the maven-assembly-plugin [3]. You also need to make the final jar
executable in this case.

[1]
http://maven.apache.org/plugins/maven-shade-plugin/examples/includes-exclude
s.html
[2]
http://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.h
tml
[3] http://maven.apache.org/plugins/maven-assembly-plugin/

/Anders


On Wed, Jun 12, 2013 at 5:35 AM, Jorge Infante Osorio <jo...@uci.cu>wrote:

> Hi all.
>
> I´m newbie in maven.
>
> I have a Maven project and I need to build a jar file with the maven 
> dependencies inside, like I do with export jar as runnable in Eclipse 
> to execute the functionality from the command line.
>
> What plugin can I use for this with what config?
>
> Thanks.
>
> Saludos,
> Ing. Jorge Infante Osorio.
> CDAE.
> Fac. 5.
> UCI.
> “En un mundo perfecto las pizzas serían una comida saludable, las 
> laptops se cargarían desde una fuente de corriente inalámbrica y todos 
> los JAR serían bundles de OSGI ”
>
>
> http://www.uci.cu
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

http://www.uci.cu


http://www.uci.cu

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


Re: Include maven dependencies inside jar file

Posted by Anders Hammar <an...@hammar.net>.
If you want the deps extracted, you need to do a combination of [1] and [2].

If you want the dep jars included in the final jar, I think you best option
is to use the maven-assembly-plugin [3]. You also need to make the final
jar executable in this case.

[1]
http://maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.html
[2]
http://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html
[3] http://maven.apache.org/plugins/maven-assembly-plugin/

/Anders


On Wed, Jun 12, 2013 at 5:35 AM, Jorge Infante Osorio <jo...@uci.cu>wrote:

> Hi all.
>
> I´m newbie in maven.
>
> I have a Maven project and I need to build a jar file with the maven
> dependencies inside, like I do with export jar as runnable in Eclipse to
> execute the functionality from the command line.
>
> What plugin can I use for this with what config?
>
> Thanks.
>
> Saludos,
> Ing. Jorge Infante Osorio.
> CDAE.
> Fac. 5.
> UCI.
> “En un mundo perfecto las pizzas serían una comida saludable, las laptops
> se
> cargarían desde una fuente de corriente inalámbrica y todos los JAR serían
> bundles de OSGI ”
>
>
> http://www.uci.cu
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>