1

I have been told that the install goal should mean that my resulting jar file will have all required dependencies included into the deployment. This, however, doesn't appear to be working for me.

Here's my pom.xml:

<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>org.zone.commandit</groupId> <artifactId>CommandIt</artifactId> <version>0.2</version> <name>CommandIt</name> <repositories> <repository> <id>bukkit-repo</id> <url>http://repo.bukkit.org/content/groups/public</url> </repository> <repository> <id>milkbowl-repo</id> <url>http://ci.herocraftonline.com/plugin/repository/everything/</url> </repository> </repositories> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.0.2</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.bukkit</groupId> <artifactId>bukkit</artifactId> <version>1.5.2-R1.0</version> <type>jar</type> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-io</artifactId> <version>1.3.2</version> </dependency> <dependency> <groupId>net.milkbowl.vault</groupId> <artifactId>Vault</artifactId> <version>1.2.26-SNAPSHOT</version> <type>jar</type> <scope>provided</scope> </dependency> <dependency> <groupId>se.krka.kahlua</groupId> <artifactId>kahlua-cldc11</artifactId> <version>5.1_2.1.0</version> </dependency> <dependency> <groupId>se.krka.kahlua</groupId> <artifactId>kahlua-core</artifactId> <version>5.1_2.1.0</version> </dependency> <dependency> <groupId>se.krka.kahlua</groupId> <artifactId>kahlua-interpreter</artifactId> <version>5.1_2.1.0</version> </dependency> <dependency> <groupId>se.krka.kahlua</groupId> <artifactId>kahlua-j2se</artifactId> <version>5.1_2.1.0</version> </dependency> </dependencies> </project> 

From this, I expect a CommandIt-0.2.jar file with commons-io and the kahlua libraries (which are installed in the local repository). The bukkit and Vault dependencies should not be included as they are provided in the runtime environment.

However, upon inspecting the project jar file with 7zip, I find only META-INF and my own source code. What am I doing wrong?

5
  • What package are you using? WAR, JAR? Commented Jun 25, 2013 at 11:01
  • Where are you looking files for? Maven dependencies are downloaded to the local maven repository, it is usually .m2 directory in your user home directory. Packaging JAR doesn't include any other JARs into the result. If you want to make a web application, use packaging WAR (or EAR). In the WAR file there are your JARs inc. all dependencies included. Commented Jun 25, 2013 at 11:13
  • 2
    With the actual configuration you are only compiling your project in a JAR, but not attaching the dependencies. Take a look to Maven assembly plugin: maven.apache.org/plugins/maven-assembly-plugin or Maven Shade plugin: maven.apache.org/plugins/maven-shade-plugin Commented Jun 25, 2013 at 11:14
  • 1
    Write an actual answer and earn yourself 5 points! Commented Jun 25, 2013 at 11:30
  • @CJxD: you mean "15" ;). Also, install installs your artifact to the local repository, which is not something you need if you just want a package - depending on whether you have anything in integration-test, either package of verify will suffice. Commented Jun 25, 2013 at 12:10

3 Answers 3

1

You can use the Maven Assembly plugin to generate a JAR containing all your dependencies.

Add the following in the build > plugins section:

<plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </plugin> 

The Maven target to run this plugin is assembly:single.

Sign up to request clarification or add additional context in comments.

Comments

0

Maven dependencies are downloaded to the local maven repository, it is usually .m2 directory in your user home directory. Packaging JAR doesn't include any other JARs into the result. If you want to make a web application, use packaging WAR (or EAR). In the WAR file there are your JARs inc. all dependencies included.

Comments

0

mvn install executes plugins which simply put whatever artifacts were built, in this case a JAR file with your code, into your local repository, typically located at ~/.m2/repository.

If you want to assemble something to distribute, like a tarball containing JARs and shell scripts, looking into the Maven assembly plugin. If you want to assemble a single JAR file containing your code and the code in your dependencies, the Maven assembly plugin can be run using the jar-with-dependencies descriptor.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.