C:\Documents and Settings\<yourID>\.m2
directory: <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
mvn install package
project_folder\target\project.zip
mvn eclipse:eclipse
mvn -Dmaven.test.skip=true -o install
lib\maven-x.x.x-uber.jar/org\apache\maven\project\pom-4.0.0.xml
).
mvn help:effective-pom
.
${…}
) interpolation
Maven vs Ant:
mvn help:describe -DgroupId=org.apache.maven.plugins -DartifactId=maven-dependency-plugin -Dfull=true
.
mvn clean package
maven-antrun-plugin
? ant-contrib
library (on example of <propertyregex>
):<plugin> <artifactId>maven-antrun-plugin</artifactId> <version>1.8</version> <dependencies> <dependency> <groupId>ant-contrib</groupId> <artifactId>ant-contrib</artifactId> <version>1.0b3</version> <exclusions> <exclusion> <groupId>ant</groupId> <artifactId>ant</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <executions> <execution> <phase>process-resources</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <taskdef resource="net/sf/antcontrib/antlib.xml" classpathref="maven.plugin.classpath" /> <propertyregex property="another.version" input="${project.version}" regexp="^(\d+)\.(\d+)\.(\d+)" select="\1-\2-\3" /> <echo message="Got ${another.version} ..." /> </tasks> </configuration> </execution> </executions> </plugin>
MAVEN_OPTS=-Xmx512m
. To increase the memory for test cycle in case when Unit test execution is run in a forked JVM, use <configuration><argLine>-Xmx756m</argLine></configuration>
option for maven-surefire-plugin
.
maven-deploy-plugin
? -B
(batch) Maven option key.
maven-surefire-plugin
to two phases (test
and integration-test
) with different configuration settings.
Also check Combining profiles in Maven to skip multiple categories of unit tests concerning how to fine-tune which tests to run.
-Dmaven.test.skip=true
) so one need to define the following profile:<profiles> <profile> <id>disable-unit-tests</id> <activation> <property> <name>maven.test.skip.myproject</name> <value>true</value> </property> </activation> <build> <pluginManagement> <plugins> <plugin> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skipTests>true</skipTests> </configuration> </plugin> </plugins> </pluginManagement> </build> </profile> </profiles>
and then say mvn -Dmaven.test.skip.myproject=true install
Unfortunately it is not possible to generalize this profile and put to parent POM, see Disable unit tests in a submodule using system property.
settings-security.xml
? -Dsettings.security=path/to/security-settings.xml
.
For example, to bypass repository vaadin-addons
use the following configuration:
<mirrors> <mirror> <url>http://repository.internal/nexus/content/groups/development</url> <mirrorOf>*,!vaadin-addons</mirrorOf> </mirror> </mirrors> <profiles> <profile> <id>extra-repositories</id> <repositories> <repository> <id>vaadin-addons</id> <url>http://maven.vaadin.com/vaadin-addons</url> </repository> </repositories> </profile> </profiles> <activeProfiles> <activeProfile>extra-repositories</activeProfile> </activeProfiles>
-SNAPSHOT
versions less frequent? -SNAPSHOT
versions each time the dependency is resolved slows down the project build. The way out is to override the default <updatePolicy>daily</updatePolicy>
in your settings.xml
and set it for 10 days (14400 minutes):<repositories> <repository> <id>central</id> <url>http://central</url> <releases> <enabled>true</enabled> <updatePolicy>daily</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>interval:14400</updatePolicy> </snapshots> </repository> </repositories>
-T
option to run build in parallel threads: alias mvnn='mvn -T4'
– always use 4 threadsalias mvnn='mvn -T1.0C'
– use number of CPUs multiplied by 1.0
(with two CPU cores the number of threads will be 2
).mvnsh
– a background process to keep maven always loaded into memory-o
switch not to update dependencies / or check How to configure Maven to check for ''-SNAPSHOT'' versions less frequent?From Takari: Maven на стероидах:
takari-local-repository-0.11.2.jar
and takari-smart-builder-0.6.1.jar
(check for later version) and put them to maven/lib/ext/
. In combination with above one can enable smart build using the following alias: alias mvnn='mvn -T1.0C --builder smart'
export MAVEN_OPTS="-Xmx1200m -XX:+TieredCompilation -XX:TieredStopAtLevel=1"
<plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <phase>initialize</phase> <goals> <goal>run</goal> </goals> <configuration> <target> <property environment="env" /> <echoproperties /> </target> </configuration> </execution> </executions> </plugin>
maven test
task? -Dname=value
(fixes SUREFIRE-121).<systemPropertyVariables>
configuration option of surefire plugin (see here): <plugin> <artifactId>maven-surefire-plugin</artifactId> <configuration> <systemPropertyVariables> <http.proxyHost>proxy</http.proxyHost> <http.proxyPort>8080</http.proxyPort> </systemPropertyVariables> </configuration> </plugin>
<systemPropertyVariables>
behaviour is broken. Also the parent JVM variables are not copied to forked JVM (see SUREFIRE-491). The only working configuration is: <plugin> <artifactId>maven-surefire-plugin</artifactId> <configuration> <argLine>-ea -Xmx756m -Dhttp.proxyHost=proxy -Dhttp.proxyPort=8080</argLine> </configuration> </plugin>
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>
<cutdirsmapper dirs="1" />
(see also <flattenmapper />
which removes all folders).<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <goals> <goal>run</goal> </goals> <configuration> <target> <move todir="${project.build.directory}/dest" verbose="true"> <fileset dir="${project.build.directory}/source"> <include name="**/*.txt" /> </fileset> <cutdirsmapper dirs="1" /> </move> </target> </configuration> </execution> </executions> </plugin>
mvn -Dmaven.test.error.ignore=true install site
mvn org.apache.maven.plugins:maven-dependency-plugin:2.9:tree > tree
maven-surefire-plugin
and exec-maven-plugin
are impacted by this issue. java.net.URL
cannot resolve protocol handler for isolated classloader which is set up by Maven. Workaround is to use custom URLStreamHandlerFactory
which can locate the handler class (e.g. provided by runtime dependency):static class HttpHandlerFactory implements URLStreamHandlerFactory { private final URLStreamHandler handler; public HttpHandlerFactory(URLStreamHandler handler) { this.handler = handler; } @Override public URLStreamHandler createURLStreamHandler(String protocol) { if (protocol.equals("http")) { return handler; } return null; } } public static void main(String[] args) throws Exception { try { Class<?> cl = Class.forName("org.mycompany.protocol.http.Handler"); URL.setURLStreamHandlerFactory(new HttpHandlerFactory((URLStreamHandler) cl.newInstance())); } catch (ClassNotFoundException e) { // Specific handler is not in the classpath } ... }
See also:
Thread.currentThread().getContextClassLoader()
.
my
in module A
to have impact on dependent module B
you need to activate a profile during a multi-module build, but build only one module (mvn -Pmy -pl B
, see here).
However it is possible to activate profiles in dependent artifact, e.g. as described in MNG-1388.
<properties> <!-- By default unit tests fail the build: --> <failOnError>true</failOnError> </properties> <profiles> <profile> <id>failOnError</id> <activation> <property> <name>failOnError</name> <value>false</value> </property> </activation> <build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <testFailureIgnore>true</testFailureIgnore> </configuration> </plugin> </plugins> </pluginManagement> </build> </profile> </profiles>
<profile> <id>doit</id> <build> <plugins> <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <id>step1</id> <phase>install</phase> <goals> <goal>run</goal> </goals> <configuration> <target> <echo message="Step 1" /> </target> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile>
And now one wants to extend this profile in module POM in a way that more steps are executed in addition to above. One need to create profile with same profile ID, but choose different execution ID:
<profile> <id>doit</id> <build> <plugins> <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <id>step2</id> <phase>install</phase> <goals> <goal>run</goal> </goals> <configuration> <target> <echo message="Step 2" /> </target> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile>
Now if mvn -Pdoit
is executed, you will see Step1 Step2
printed to console.
For more advanced merging facilities check Maven How-To: Merging Plugin Configuration in Complex Projects (combine.children="append"
to append children, combine.self="override"
to ignore children for the parent being overridden). Note that you can't merge e.g. build.resources
the same way: use build-helper-maven-plugin
to achieve that:
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <executions> <execution> <phase>initialize</phase> <goals> <goal>add-resource</goal> </goals> <configuration> <resources> <resource> <directory>src/main/extra</directory> </resource> </resources> </configuration> </execution> </executions> </plugin>
mvn dependency:tree
. And see here.
dependencyManagement
with import
scope (example was taken from here):<dependencyManagement> <dependencies> <dependency> <groupId>org.test</groupId> <artifactId>common-libs</artifactId> <version>1.0</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
Note that version ranges are not supported if dependencies are inherited either from parent POM or the way above (see MNG-2199).
mvn -X
output.
war
?
war
packaging in your pom.xml
and you want to create a JAR file together 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
In latest WAR plugin versions it is possible to specify the attachClasses option to achieve the same effect: <configuration><attachClasses>true</attachClasses></configuration>
. Also using profiles like in Building For Different Environments with Maven 2 may help.
META-INF/context.xml
), then it should be placed to src/webapp/META-INF/context.xml
.META-INF/aop.xml
, or Hibernate META-INF/hibernate.xml
, or any other via String#getResource()
), then it should be placed to src/main/resources/META-INF/aop.xml
.
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>
For the WAR file (e.g. when adding an applet) use the same technique:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <phase>prepare-package</phase> <goals> <goal>copy</goal> </goals> <configuration> <artifactItems> <artifactItem> <groupId>${project.groupId}</groupId> <artifactId>applet-artifact-id</artifactId> </artifactItem> </artifactItems> <outputDirectory>${project.build.directory}/${project.build.finalName}/applet</outputDirectory> <stripVersion>true</stripVersion> </configuration> </execution> </executions> </plugin>
test-common
project add to your pom the following:<project ...> <build> <plugins> <plugin> <artifactId>maven-jar-plugin</artifactId> <executions> <execution> <goals> <goal>test-jar</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
and then use the resulting jar artifact with tests
classifier in test
scope:
<project ...> <dependencies> <dependency> <groupId>${project.groupId}</groupId> <artifactId>text-common</artifactId> <version>0.1</version> <classifier>tests</classifier> <scope>test</scope> </dependency> </dependencies> </project>
maven-shade-plugin
or maven-jar-plugin
2), we need to create ZIP file which after unpacking will result run.cmd
and all dependencies in lib
folder. This gives more control over the JVM settings (e.g. heap size).<?xml version="1.0" encoding="UTF-8"?> <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/maven-v4_0_0.xsd"> ... <properties> <main.class>package.Main</main.class> <classpath.prefix>lib</classpath.prefix> </properties> <dependencies> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <scope>runtime</scope> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>build-classpath</id> <phase>package</phase> <goals> <goal>build-classpath</goal> </goals> <configuration> <prefix>${classpath.prefix}</prefix> <outputProperty>classpath.all</outputProperty> </configuration> </execution> </executions> </plugin> <plugin> <artifactId>maven-assembly-plugin</artifactId> <executions> <execution> <id>assemble-zip-package</id> <phase>package</phase> <goals> <goal>single</goal> </goals> <configuration> <descriptors> <descriptor>src/main/package/assembly.xml</descriptor> </descriptors> <appendAssemblyId>false</appendAssemblyId> </configuration> </execution> </executions> </plugin> <!-- This will suppress generation of JAR artifact: --> <plugin> <artifactId>maven-jar-plugin</artifactId> <executions> <execution> <id>default-jar</id> <phase>dummy</phase> </execution> </executions> </plugin> </plugins> </build> </project>
<?xml version="1.0" encoding="UTF-8"?> <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> <id>package</id> <formats> <format>zip</format> </formats> <baseDirectory /> <dependencySets> <dependencySet> <outputDirectory>${classpath.prefix}</outputDirectory> </dependencySet> </dependencySets> <fileSets> <fileSet> <directory>${build.outputDirectory}</directory> <outputDirectory>${classpath.prefix}</outputDirectory> </fileSet> </fileSets> <files> <file> <source>src/main/package/run.cmd</source> <outputDirectory>/</outputDirectory> <filtered>true</filtered> </file> </files> </assembly>
Note that adding the lib
folder to classpath is necessary as that folder will contain e.g. main class as well as resources:
java -cp "${classpath.prefix}${path.separator}${classpath.all}" ${main.class} %1
Try maven-shade-plugin
:
<properties> <jar.final.classifier>all</jar.final.classifier> </properties> <plugin> <artifactId>maven-shade-plugin</artifactId> <version>2.0</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <minimizeJar>true</minimizeJar> <shadedArtifactAttached>true</shadedArtifactAttached> <shadedClassifierName>${jar.final.classifier}</shadedClassifierName> <filters> <filter> <artifact>commons-logging:commons-logging</artifact> <includes> <include>**</include> </includes> </filter> </filters> </configuration> </execution> </executions> </plugin>
Try GenJar (generally, didn't worked well for me):
org.apache.tools
package from resulting build/lib/genjar.jar
(otherwise there will be problems as maven-antrun-plugin
is compiled against future versions of Ant).mvn install:install-file -Dfile=genjar.jar -DgroupId=net.sf.genjar -DartifactId=genjar -Dversion=1.0 -Dpackaging=jar
<properties> <main.class>org.mycompany.myproject.Main</main.class> <jar.final.classifier>all</jar.final.classifier> <jar.final.name>${project.build.directory}/${project.artifactId}-${project.version}-${jar.final.classifier}.jar</jar.final.name> </properties> <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <id>minify-jar</id> <phase>package</phase> <goals> <goal>run</goal> </goals> <configuration> <target name="minify-jar"> <!-- Check maven-antrun-plugin manual concerning build-in classpath references: http://maven.apache.org/plugins/maven-antrun-plugin/examples/classpaths.html --> <taskdef resource="genjar.properties" classpathref="maven.plugin.classpath" /> <genjar jarfile="${jar.final.name}"> <class name="${main.class}" /> <classpath> <pathelement location="${project.build.directory}/${project.artifactId}-${project.version}.jar" /> </classpath> <manifest> <attribute name="Implementation-Title" value="${project.name}" /> <attribute name="Implementation-Version" value="${project.version}" /> <attribute name="Implementation-Vendor" value="${project.organization.name}" /> <attribute name="Implementation-Vendor-Id" value="${project.groupId}" /> <attribute name="Main-Class" value="${main.class}" /> </manifest> </genjar> <attachartifact file="${jar.final.name}" classifier="${jar.final.classifier}"/> </target> </configuration> </execution> </executions> <dependencies> <dependency> <groupId>net.sf.genjar</groupId> <artifactId>genjar</artifactId> <version>1.0</version> </dependency> </dependencies> </plugin>
Try ProGuard:
<properties> <main.class>org.mycompany.myproject.Main</main.class> <jar.assembly.classifier>jar-with-dependencies</jar.assembly.classifier> <jar.final.classifier>all</jar.final.classifier> </properties> <plugin> <artifactId>maven-assembly-plugin</artifactId> <executions> <execution> <id>package-jar-with-dependencies</id> <phase>package</phase> <goals> <goal>single</goal> </goals> <configuration> <descriptorRefs> <descriptorRef>${jar.assembly.classifier}</descriptorRef> </descriptorRefs> <appendAssemblyId>true</appendAssemblyId> <attach>false</attach> <archive> <manifest> <addDefaultImplementationEntries>true</addDefaultImplementationEntries> </manifest> </archive> </configuration> </execution> </executions> </plugin> <plugin> <groupId>com.github.wvengen</groupId> <artifactId>proguard-maven-plugin</artifactId> <version>2.0.6</version> <executions> <execution> <id>minify-jar</id> <phase>package</phase> <goals> <goal>proguard</goal> </goals> <configuration> <addMavenDescriptor>true</addMavenDescriptor> <attachArtifactClassifier>${jar.final.classifier}</attachArtifactClassifier> <attach>true</attach> <includeDependency>false</includeDependency> <obfuscate>false</obfuscate> <injar>${project.artifactId}-${project.version}-${jar.assembly.classifier}.jar</injar> <options> <option>-keep class ${main.class} { public static void main(java.lang.String[]); }</option> <option>-keep class org.apache.commons.logging.impl.LogFactoryImpl { *; }</option> <option>-keep class org.apache.commons.logging.impl.Log4JLogger { *; }</option> <option>-dontoptimize</option> <option>-ignorewarnings</option> </options> <!-- Additional libs to search dependencies in: --> <libs> <lib>${java.home}/lib/rt.jar</lib> <lib>${java.home}/lib/jsse.jar</lib> </libs> </configuration> </execution> </executions> <dependencies> <dependency> <groupId>net.sf.proguard</groupId> <artifactId>proguard-base</artifactId> <version>4.8</version> <scope>runtime</scope> </dependency> </dependencies> </plugin>
java.lang.ClassFormatError: LVTT entry for ... does not match any LVT entry
is solved by adding -optimizations !code/allocation/variable
(from here).ClassFormatError: Invalid index N in LocalVariableTable in class file …
is solved by using -dontoptimize
(see Troubleshooting).Finally, check other alternatives.
jar
MANIFEST?
One need to enable filtering and use additional bridging variable, for example ${timestamp}
:
<properties> <timestamp>${maven.build.timestamp}</timestamp> <maven.build.timestamp.format>yyyy-MM-dd</maven.build.timestamp.format> </properties> <build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> </build>
Another alternative is to use buildnumber-maven-plugin
. To achieve this one need to activate buildnumber-maven-plugin
twice (one per each goal):
<build> <pluginManagement> <plugins> <plugin> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <addDefaultImplementationEntries>true</addDefaultImplementationEntries> </manifest> <manifestEntries> <Scm-Url>${project.scm.developerConnection}</Scm-Url> <Implementation-Build>${project.buildNumber}</Implementation-Build> <Implementation-Build-Date>${project.buildDate}</Implementation-Build-Date> </manifestEntries> </archive> </configuration> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <configuration> <archive> <manifest> <addDefaultImplementationEntries>true</addDefaultImplementationEntries> </manifest> <manifestEntries> <Scm-Url>${project.scm.developerConnection}</Scm-Url> <Implementation-Build>${project.buildNumber}</Implementation-Build> <Implementation-Build-Date>${project.buildDate}</Implementation-Build-Date> </manifestEntries> </archive> </configuration> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>buildnumber-maven-plugin</artifactId> <executions> <execution> <id>create-buildnumber</id> <phase>validate</phase> <goals> <goal>create</goal> </goals> <configuration> <buildNumberPropertyName>project.buildNumber</buildNumberPropertyName> </configuration> </execution> <execution> <id>create-timestamp</id> <phase>validate</phase> <goals> <goal>create-timestamp</goal> </goals> <configuration> <timestampFormat>yyyy-MM-dd</timestampFormat> <timestampPropertyName>project.buildDate</timestampPropertyName> </configuration> </execution> </executions> </plugin> </plugins> </build>
repo1
with wget. Why? $ wget -S http://repo1.maven.org/maven2/org/apache/commons/commons-compress/1.0/commons-compress-1.0.jar.md5 --22:44:21-- http://repo1.maven.org/maven2/org/apache/commons/commons-compress/1.0/commons-compress-1.0.jar.md5 => `commons-compress-1.0.jar.md5' Resolving repo1.maven.org... 38.97.124.18 Connecting to repo1.maven.org|38.97.124.18|:80... connected. HTTP request sent, awaiting response... HTTP/1.1 403 Forbidden Server: nginx/0.7.62 Date: Mon, 08 Mar 2010 21:44:26 GMT Content-Type: text/html Content-Length: 169 Connection: keep-alive 22:44:21 ERROR 403: Forbidden.
but this succeeds:
22:44 ws1.grid.sara.nl:/home/dmitry dmitry$ man wget 22:44 ws1.grid.sara.nl:/home/dmitry dmitry$ wget -S --user-agent="Mozilla" http://repo1.maven.org/maven2/org/apache/commons/commons-compress/1.0/commons-compress-1.0.jar.md5 --22:44:52-- http://repo1.maven.org/maven2/org/apache/commons/commons-compress/1.0/commons-compress-1.0.jar.md5 => `commons-compress-1.0.jar.md5' Resolving repo1.maven.org... 38.97.124.18 Connecting to repo1.maven.org|38.97.124.18|:80... connected. HTTP request sent, awaiting response... HTTP/1.1 200 OK Server: nginx/0.7.62 Date: Mon, 08 Mar 2010 21:44:57 GMT Content-Type: text/plain Content-Length: 75 Last-Modified: Fri, 10 Jul 2009 20:11:52 GMT Connection: keep-alive Accept-Ranges: bytes Length: 75 [text/plain] 100%[====================================================================================>] 75 --.--K/s
<settings> <servers> <server> <id>local-server-id</id> <username>tomcat</username> <password>Ab1nXmI</password> </server> </servers> </settings>
This user should have “manager” rights in Tomcat server config:
<tomcat-users> ... <user username="tomcat" password="Ab1nXmI" roles="manager"/> </tomcat-users>
Now we add the plugin to pom.xml
for service (and for client, but changing the deployment context path):
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>tomcat-maven-plugin</artifactId> <configuration> <!-- Server credentials are stored in settings.xml: --> <server>local-server-id</server> <url>http://local-server.net:8080/manager</url> <!-- Deployment context: --> <path>/my-manager</path> </configuration> </plugin>
and use mvn tomcat:deploy
or later mvn tomcat:redeploy
3) to do the job:
... [INFO] ------------------------------------------------------------------------ [INFO] Building RDF Storage Web Service [INFO] task-segment: [tomcat:redeploy] [INFO] ------------------------------------------------------------------------ ... [INFO] [tomcat:redeploy] [INFO] Deploying war to http://local-server.net:8080/my-manager [INFO] OK - Undeployed application at context path /my-manager [INFO] OK - Deployed application at context path /my-manager [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------
scp
the artifact to JBoss deploy directory (make sure you have org.jboss.deployment.scanner.URLDeploymentScanner
bean enabled in conf/jboss-service.xml
).
For example you can do it by binding to deploy
phase so that artifact is deployed from CI server each time on successful build:
<build> <pluginManagement> <plugins> <!-- SCP the artifact to remote JBoss: --> <plugin> <artifactId>maven-antrun-plugin</artifactId> <version>1.4</version> <executions> <execution> <phase>deploy</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <!-- You need to run "pscp.exe" once in advance for it to store the server's public key into registry [HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys] --> <!-- Passing the command to CMD allows to delegate argument split & environment variables substitution to CMD. --> <exec executable="cmd"> <arg value= "/C" /> <arg value= "pscp.exe -batch -i "%USERPROFILE%/.ssh/id.ppk" ${project.build.directory}/${project.artifactId}-${project.version}.ear ${jboss.server.host}:${jboss.server.deploydir}" /> </exec> </tasks> </configuration> </execution> </executions> </plugin> </plugins> </pluginManagement> </build>
or artifact is deployed when you run mvn antrun:run
manually:
<build> <pluginManagement> <plugins> <!-- SCP the artifact to remote JBoss: --> <plugin> <artifactId>maven-antrun-plugin</artifactId> <version>1.7</version> <configuration> <target> <!-- You need to run "scp.exe" once in advance for it to store the server's public key into %USERPROFILE%\.ssh\known_hosts --> <!-- All arguments should be manually split. --> <exec executable="scp.exe"> <arg value="-q" /> <!-- ${project.build.directory} substitution will not work here as scp will interpret "C:" as host --> <arg value="target/${project.artifactId}-${project.version}.ear" /> <arg value="${jboss.server.host}:${jboss.server.deploydir}" /> </exec> </target> </configuration> </plugin> </plugins> </pluginManagement> </build>
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:
release:prepare release:perform -Dresume=false
… -Dusername=john -Dpassword=nnn
… -DreleaseVersion=${RELEASE_VERSION} -DdevelopmentVersion=${DEVELOPMENT_VERSION}
release:prepare release:perform -Dusername=john -Dpassword=abc123
:
If you need to pass version numbers from user, you need to wrap the call to maven into bash script as when releaseVersion and developmentVersion are passed in command-line but are empty they are not treated as not-defined.
maven-release-plugin
will use project.scm.developerConnection
(or project.scm.connection
if the last one is not defined) to commit to source repository and project.distributionManagement
for artifact deployment. So your pom.xml
may look like this: <project> <modelVersion>4.0.0</modelVersion> <groupId>org.mycompany.project</groupId> <artifactId>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>
maven-release-plugin
to complain with message Cannot prepare the release because you have local modifications
. To exclude these files from being checked use <checkModificationExcludes>
or pass via CLI, e.g. -DcheckModificationExcludeList=.maven
(see How to disable maven release plugin check local modifications?).
Some helpful information for maven release plugin:
Concerning multi-project release:
Books:
Other:
release:prepare
? versions-maven-plugin
in combination with preparationGoals
setting:<build> <pluginManagement> <plugins> <plugin> <artifactId>maven-release-plugin</artifactId> <version>2.5.3</version> <configuration> <autoVersionSubmodules>true</autoVersionSubmodules> <preparationGoals>versions:update-parent clean verify</preparationGoals> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>versions-maven-plugin</artifactId> <version>2.11.0</version> <configuration> <generateBackupPoms>false</generateBackupPoms> </configuration> </plugin> </plugins> </pluginManagement> </build>
mvn release:prepare
fails with message svn: OPTIONS of Server certificate verification failed: issuer is not trusted
mvn release:prepare
fails with message svn: '/tags/java/project' path not found
Plugin XXX does not exist or no valid version could be found
mvn -U ...
(see FAQ)org.apache.maven.plugins
or org.codehaus.mojo
, then add to your settings.xml
(see maven's documentation): <settings ...> <pluginGroups> <pluginGroup>org.mortbay.jetty</pluginGroup> </pluginGroups> </settings>
<properties> <maven.scm.svnjava.version>2.0.5</maven.scm.svnjava.version> <svnkit.version>1.7.8</svnkit.version> <!-- This dependency is optional. To be sure that all plugins are bound to one SVNKit version. --> </properties> ... <plugin> <artifactId>maven-release-plugin</artifactId> <configuration> ... </configuration> <dependencies> <dependency> <groupId>com.google.code.maven-scm-provider-svnjava</groupId> <artifactId>maven-scm-provider-svnjava</artifactId> <version>${maven.scm.svnjava.version}</version> </dependency> <dependency> <groupId>org.tmatesoft.svnkit</groupId> <artifactId>svnkit</artifactId> <version>${svnkit.version}</version> </dependency> </dependencies> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>buildnumber-maven-plugin</artifactId> <executions> ... </executions> <dependencies> <dependency> <groupId>com.google.code.maven-scm-provider-svnjava</groupId> <artifactId>maven-scm-provider-svnjava</artifactId> <version>${maven.scm.svnjava.version}</version> </dependency> <dependency> <groupId>org.tmatesoft.svnkit</groupId> <artifactId>svnkit</artifactId> <version>${svnkit.version}</version> </dependency> </dependencies> </plugin>
"Девица не хочет лезть в Окно" – device not compatible with Windows.