Hi QL,
Could you please supply me with an example of a executable
> jar-with-dependencies?
>
We build an executable JAR-with-dependencies using the assembly plugin.
There are two issues:
1) Including all the dependencies in the JAR. In your assembly descriptor,
use:
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
2) Setting the main class for the combined JAR. In your POM, use:
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/all.xml</descriptor>
</descriptors>
<finalName>imagej-${project.version}</finalName>
<archive>
<manifest>
<mainClass>imagej.Main</mainClass>
</manifest>
</archive>
</configuration>
If you want a working example, you can check the ImageJ2 codebase here:
https://github.com/imagej/imagej/blob/master/ui/app/pom.xml
https://github.com/imagej/imagej/blob/master/ui/app/src/main/assembly/all.xml
Just be warned there is a fair bit of nastiness and complexity in there
that is very unlikely to be necessary for your use case.
HTH,
Curtis
On Tue, Apr 17, 2012 at 5:23 PM, QL 983 <[email protected]> wrote:
> Hi, Anders; thank you for your answer! I tried using useProjectArtifact
> false, but it did not work.
>
> Could you please supply me with an example of a executable
> jar-with-dependencies?
>
> Kind regards,
>
> QL
>
> On Tue, Apr 17, 2012 at 8:06 AM, Anders Hammar <[email protected]> wrote:
>
> > I think the solution is to set useProjectArtifact to false in the
> > assembly descriptor.
> >
> > /Anders
> >
> > On Tue, Apr 17, 2012 at 11:44, QL 983 <[email protected]> wrote:
> > > Hi.
> > >
> > > I am writing a little tutorial in my company about the use of the Maven
> > > Assembly Plugin to build a executable jar, with all dependencies inside
> > it.
> > >
> > > When I was using Maven 2.2.1, the following would done the job:
> > >
> > > ...
> > > <build>
> > > <plugins>
> > > ...
> > > <plugin>
> > > <artifactId>maven-assembly-plugin</artifactId>
> > > <configuration>
> > > <source>1.5</source>
> > > <target>1.5</target>
> > > <archive>
> > > <manifest>
> > > <mainClass>com.company.classX</mainClass>
> > > </manifest>
> > > </archive>
> > > <descriptorRefs>
> > > <descriptorRef>jar-with-dependencies</descriptorRef>
> > > </descriptorRefs>
> > > </configuration>
> > > </plugin>
> > > ...
> > > </plugins>
> > > </build>
> > > ...
> > >
> > >
> > > This time, however, I am using Maven 3.0.4, and I am getting this
> > warning:
> > >
> > >
> > > [WARNING] Cannot include project artifact: com.company.class; it
> doesn't
> > > have an associated file or directory.
> > >
> > >
> > > I read the plugin's documentation, but could not figure what is the
> > problem.
> > >
> > > Here is the complete pom I am using now:
> > >
> > >
> > > <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/xsd/maven-4.0.0.xsd">
> > > <modelVersion>4.0.0</modelVersion>
> > > <groupId>com.company</groupId>
> > > <artifactId>tutorial</artifactId>
> > > <version>1.0-SNAPSHOT</version>
> > > <packaging>jar</packaging>
> > > <name>someName</name>
> > > <url>http://maven.apache.org</url>
> > > <properties>
> > > <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
> > > <compileSource>1.6</compileSource>
> > > </properties>
> > > <build>
> > > <plugins>
> > > <plugin>
> > > <artifactId>maven-compiler-plugin</artifactId>
> > > <version>2.0.2</version>
> > > <configuration>
> > > <source>${compileSource}</source>
> > > <target>${compileSource}</target>
> > > </configuration>
> > > </plugin>
> > >
> > > <plugin>
> > > <artifactId>maven-assembly-plugin</artifactId>
> > > <version>2.3</version>
> > > <configuration>
> > >
> > > <archive>
> > > <manifest>
> > > <mainClass>com.company.classX</mainClass>
> > > </manifest>
> > > </archive>
> > > <descriptorRefs>
> > > <descriptorRef>jar-with-dependencies</descriptorRef>
> > > </descriptorRefs>
> > > </configuration>
> > > <executions>
> > > <execution>
> > > <id>make-assembly</id> <!-- this is used for inheritance
> > merges
> > > -->
> > > <phase>package</phase> <!-- bind to the packaging phase -->
> > > <goals>
> > > <goal>single</goal>
> > > </goals>
> > > </execution>
> > > </executions>
> > > </plugin>
> > >
> > > </plugins>
> > > </build>
> > >
> > > <dependencies>
> > >
> > > <dependency>
> > > <groupId>org.apache.httpcomponents</groupId>
> > > <artifactId>httpclient</artifactId>
> > > <version>4.1.3</version>
> > > </dependency>
> > >
> > > </dependencies>
> > >
> > > </project>
> > >
> > >
> > > The resulting jar contains httpclient and all the dependencies it has,
> > but
> > > no code of mine is added in the jar, and I get this output in command
> > line:
> > >
> > >
> > > D:\projetos\tutorial>mvn assembly:single
> > > [INFO] Scanning for projects...
> > > [INFO]
> > > [INFO]
> > >
> ------------------------------------------------------------------------
> > > [INFO] Building tutorial 1.0-SNAPSHOT
> > > [INFO]
> > >
> ------------------------------------------------------------------------
> > > [INFO]
> > > [INFO] --- maven-assembly-plugin:2.3:single (default-cli) @ tutorial
> ---
> > > *[WARNING] Cannot include project artifact:
> > > com.company:tutorial:jar:1.0-SNAPSHOT; it doesn't have an associated
> file
> > > or directory.*
> > > [INFO] META-INF/ already added, skipping
> > > [INFO] META-INF/MANIFEST.MF already added, skipping
> > > [INFO] org/ already added, skipping
> > > [INFO] org/apache/ already added, skipping
> > > [INFO] org/apache/http/ already added, skipping
> > > [INFO] org/apache/http/impl/ already added, skipping
> > > [INFO] META-INF/NOTICE.txt already added, skipping
> > > [INFO] META-INF/LICENSE.txt already added, skipping
> > > [INFO] META-INF/maven/ already added, skipping
> > > [INFO] META-INF/maven/org.apache.httpcomponents/ already added,
> skipping
> > > [INFO] META-INF/ already added, skipping
> > > [INFO] META-INF/MANIFEST.MF already added, skipping
> > > [INFO] org/ already added, skipping
> > > [INFO] org/apache/ already added, skipping
> > > [INFO] META-INF/maven/ already added, skipping
> > > [INFO] META-INF/ already added, skipping
> > > [INFO] META-INF/MANIFEST.MF already added, skipping
> > > [INFO] org/ already added, skipping
> > > [INFO] org/apache/ already added, skipping
> > > [INFO] org/apache/commons/ already added, skipping
> > > [INFO] META-INF/LICENSE.txt already added, skipping
> > > [INFO] META-INF/NOTICE.txt already added, skipping
> > > [INFO] META-INF/maven/ already added, skipping
> > > [INFO] Building jar:
> > >
> >
> D:\projetos\tutorial\target\tutorial-1.0-SNAPSHOT-jar-with-dependencies.jar
> > > [INFO] META-INF/ already added, skipping
> > > [INFO] META-INF/MANIFEST.MF already added, skipping
> > > [INFO] org/ already added, skipping
> > > [INFO] org/apache/ already added, skipping
> > > [INFO] org/apache/http/ already added, skipping
> > > [INFO] org/apache/http/impl/ already added, skipping
> > > [INFO] META-INF/NOTICE.txt already added, skipping
> > > [INFO] META-INF/LICENSE.txt already added, skipping
> > > [INFO] META-INF/maven/ already added, skipping
> > > [INFO] META-INF/maven/org.apache.httpcomponents/ already added,
> skipping
> > > [INFO] META-INF/ already added, skipping
> > > [INFO] META-INF/MANIFEST.MF already added, skipping
> > > [INFO] org/ already added, skipping
> > > [INFO] org/apache/ already added, skipping
> > > [INFO] META-INF/maven/ already added, skipping
> > > [INFO] META-INF/ already added, skipping
> > > [INFO] META-INF/MANIFEST.MF already added, skipping
> > > [INFO] org/ already added, skipping
> > > [INFO] org/apache/ already added, skipping
> > > [INFO] org/apache/commons/ already added, skipping
> > > [INFO] META-INF/LICENSE.txt already added, skipping
> > > [INFO] META-INF/NOTICE.txt already added, skipping
> > > [INFO] META-INF/maven/ already added, skipping
> > > [INFO]
> > >
> ------------------------------------------------------------------------
> > > [INFO] BUILD SUCCESS
> > > [INFO]
> > >
> ------------------------------------------------------------------------
> > > [INFO] Total time: 1.437s
> > > [INFO] Finished at: Tue Apr 17 06:38:42 BRT 2012
> > > [INFO] Final Memory: 4M/15M
> > > [INFO]
> > >
> ------------------------------------------------------------------------
> > > D:\projetos\tutorial>
> > >
> > >
> > > Does anyone please have any idea? I am getting crazy with this
> problem.
> > >
> > > Thank you very much,
> > > Kind regards,
> > >
> > > QL.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [email protected]
> > For additional commands, e-mail: [email protected]
> >
> >
>