<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <proxies> <proxy> <id>mylocalproxy</id> <active>true</active> <protocol>http</protocol> <host>proxy</host> <port>8080</port> <!-- <nonProxyHosts> *.google.com|ibiblio.org</nonProxyHosts> --> </proxy> </proxies> </settings>
call mvn install:install-file -Dversion=0.1-SNAPSHOT -Dpackaging=jar -DgroupId=org.company.package -DartifactId=library-name -Dfile=library.jar
Note: Unfortunately, it is hardly possible to make an assembly in nn_build project (see 1, 2, 3). So the assembly is done in a project, which contains the main class. This allows also the assembly to be bound to «package» goal.
Q: I want to install WAR file together with JAR file, i.e. how can I make maven to create and install two artifacts with different packaging?
A: If you have a war packaging in your pom.xml and you want to create a JAR file togуther with WAR file, try this command: mvn -o jar:jar install:install-file -Dfile=${project.build.directory}\${project.artifactId}-${project.version}.jar -Dpackaging=jar -DpomFile=pom.xml. Also using profiles like in Building For Different Environments with Maven 2 may help.
For those, who want to make a release from a command line, I would refer them to look at maven-release-plugin (see good reference here). Here we will setup the following infrastructure:
So, what you need to do:
<project> <modelVersion>4.0.0</modelVersion> <groupId>org.erasmusmc.rdf-storage</groupId> <artifactId>rdf-storage-service</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>My Service</name> <scm> <connection>scm:svn:https://localserver.com/svn/trunk/java/projects/myservice</connection> </scm> <distributionManagement> <repository> <id>nexus-server-id</id> <url>http://mavenserver.com/nexus/content/repositories/releases</url> </repository> <snapshotRepository> <id>nexus-server-id</id> <url>http://mavenserver.com/nexus/content/repositories/snapshots</url> </snapshotRepository> </distributionManagement> ... </project>
Some helpful information:
Concerning multi-project release:
Q: Where I can get more detailed explanation about POM?
A: See here.
Q: mvn release:prepare fails with message svn: OPTIONS of Server certificate verification failed: issuer is not trusted
A: You need to run the svn list ... command manually under the specified user (possibly, changing the user via sudo -u host_user -H /bin/bash3) ), and then accept the server's certificate permanently4).
Q: mvn release:prepare fails with message svn: '/tags/java/project' path not found.
A: This happens because plugin does not create parent path entries when tagging. See release:prepare should create the SVN tags parent dir if it doesn't already exist for more details.
Q: How to configure several source directories for maven project? A: This can be achieved using build-helper-maven-plugin like below:
<project> <modelVersion>4.0.0</modelVersion> <groupId>org.mycompany</groupId> <artifactId>project</artifactId> <packaging>jar</packaging> <version>1.1</version> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <executions> <execution> <id>add-source</id> <phase>generate-sources</phase> <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>${basedir}/import</source> </sources> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
Q: How to share resources between maven projects?
A: See here and here. The example below shows how to copy resources from supplier-project to consumer-project/target/addon folder:
<project> <modelVersion>4.0.0</modelVersion> <groupId>org.mycompany</groupId> <artifactId>consumer-project</artifactId> <packaging>jar</packaging> <version>1.1</version> <dependencies> <dependency> <groupId>org.mycompany.common</groupId> <artifactId>supplier-project</artifactId> <version>1.0</version> <scope>provided</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <!-- Copy shared resources: --> <execution> <phase>generate-sources</phase> <goals> <goal>unpack-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/addon</outputDirectory> <includeGroupIds>org.mycompany.common</includeGroupIds> <includeArtifacIds>supplier-project</includeArtifacIds> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
Q: How to share test code between projects?
A: For the test-common project add to your pom and then use the resulting jar artefact with tests classifier in test scope:
<project ...> <build> <plugins> <plugin> <artifactId>maven-jar-plugin</artifactId> <executions> <execution> <goals> <goal>test-jar</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
Q: What is the build phases sequence (lifecycle)?
A: See here.
Q: How to exclude dependencies from dependent tree?
A: To view the dependency tree use mvn dependency:tree. And see here.
Q: How to define Java heap space for maven?
A: MAVEN_OPTS=-Xmx512m
Q: How to deploy .jar artifact next to .war artifact when pom packaging is war?
A: Use mvn jar:jar install:install-file -Dfile=${project.build.directory}\${project.artifactId}-${project.version}.jar -Dpackaging=jar
Q: Where can I get more information about maven?
A: Read Maven Book: The Definitive Guide.