0. useful commands:
mvn install:install-file -DgroupId=org.apache.maven.archetypes -DartifactId=${myArtifactId} -Dversion=RELEASE -Dpackaging=jar -Dfile=/path/to/file
mvn deploy:deploy-file -DgroupId=org.apache.maven.archetypes -DartifactId=${myArtifactId} -Dversion=RELEASE -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
mvn -Dtest=MenuItemFacadeTest test
mvn archetype:create -DarchetypeArtifactId=maven-archetype-webapp -DgroupId=${groupId} -DartifactId=${artifactId}
mvn archetype:create -DgroupId=${groupId} -DartifactId=${artifactId}
mvn archetype:create \
-DarchetypeGroupId=<archetype-groupId> \
-DarchetypeArtifactId=<archetype-artifactId> \
-DarchetypeVersion=<archetype-version> \
-DgroupId=<my.groupid> \
-DartifactId=<my-artifactId>
1. setting resource files:
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.tld</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
</build>
2. compiler plugin:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
3. tomcat plugin(mvn tomcat:run):
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.0-beta-1</version>
<configuration>
<path>/trsWeb</path>
<port>9080</port>
</configuration>
</plugin>
4. jetty plugin(mvn jetty:run):
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.24</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<contextPath>/trsWeb</contextPath>
<connectors>
<connector implementation="org.mortbay.jetty.bio.SocketConnector">
<port>9080</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>
</plugin>
jetty-debug.bat:
@echo off
if "%OS%" == "Windows_NT" setlocal
set MAVEN_OPTS=-Xdebug -Xmx512m -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=n
mvn jetty:run
5. antrun plugin(mvn package):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>package</id>
<phase>package</phase>
<configuration>
<tasks if="${boolVariable}">
<property name="compile_classpath" refid="maven.compile.classpath"/>
<property name="runtime_classpath" refid="maven.runtime.classpath"/>
<property name="test_classpath" refid="maven.test.classpath"/>
<property name="plugin_classpath" refid="maven.plugin.classpath"/>
<echo message="compile classpath: ${compile_classpath}"/>
<echo message="runtime classpath: ${runtime_classpath}"/>
<echo message="test classpath: ${test_classpath}"/>
<echo message="plugin classpath: ${plugin_classpath}"/>
<copy file="d:/1.txt" tofile="d:/2.txt"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
or: mvn antrun:run
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.4</version>
<configuration>
<tasks if="${build.prod}">
<property name="basedir" value="${basedir}" />
<property name="compile_classpath" refid="maven.compile.classpath" />
<property name="runtime_classpath" refid="maven.runtime.classpath" />
<property name="test_classpath" refid="maven.test.classpath" />
<property name="plugin_classpath" refid="maven.plugin.classpath" />
<property name="build.dir" value="${project.build.directory}" />
<property name="dist" value="${build.dir}/dist" />
<property name="dist.src" value="${dist}/src" />
<ant antfile="${basedir}/m2-build.xml">
<target name="${build.task}" />
</ant>
</tasks>
</configuration>
</plugin>
6. profiles.xml
<?xml version="1.0" encoding="UTF-8"?>
<profilesXml>
<profiles>
<profile>
<id>development</id>
<properties>
<maven.test.skip>true</maven.test.skip>
</properties>
</profile>
<profile>
<id>production</id>
<properties>
<maven.test.skip>false</maven.test.skip>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>development</activeProfile>
</activeProfiles>
</profilesXml>
tip: the maven can auto detect the profiles.xml at the same directory with pom.xml, and use it.
7. active profile dynamically:
1. write activation condition in each profile:
<activation>
<property>
<name>env</name>
<value>was</value>
</property>
</activation>
2. define the default ${env} property in pom.xml:
<properties>
<env>dev</env>
</properties>
3. don't specify any activiate profile in neither pom.xml nor profiles.xml
4. mvn package -Denv=was
8. encoding resource copying:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
9. 3 ways to run Java main from Maven£º
1) Running from Command line
01. mvn compile
02. mvn exec:java -Dexec.mainClass="com.vineetmanohar.module.Main" <------- no args
03. mvn exec:java -Dexec.mainClass="com.vineetmanohar.module.Main" -Dexec.args="arg0 arg1 arg2" -Dexec.commandlineArgs="-Xloggc:<file>" <------- with args
04. mvn exec:java -Dexec.mainClass="com.vineetmanohar.module.Main" -Dexec.classpathScope=runtime <------- with runtime dependencies in classpath
2) Running in a phase in pom.xml
01. <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.vineetmanohar.module.CodeGenerator</mainClass>
<arguments>
<argument>arg0</argument>
<argument>arg1</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
02. mvn test
3) Running in a profile in pom.xml
01. <profiles>
<profile>
<id>code-generator</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.vineetmanohar.module.CodeGenerator</mainClass>
<arguments>
<argument>arg0</argument>
<argument>arg1</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
02. mvn test -Pcode-generator
4) Advanced options:
01. You can get a list of all available parameters by typing:
mvn exec:help -Ddetail=true -Dgoal=java
10. mvn dependency:copy-dependencies
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<outputDirectory>m2_repo</outputDirectory>
<overWriteIfNewer>true</overWriteIfNewer>
<useRepositoryLayout>true</useRepositoryLayout>
<copyPom>true</copyPom>
</configuration>
</plugin>
11. deploy snapshot/3rd party maven project to nexus:
pom.xml
------------------------------------------------------------------------------------------
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Nexus142 Release Repository</name>
<url>http://10.199.130.142:8080/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus142 Snapshot Repository</name>
<url>http://10.199.130.142:8080/nexus/content/repositories/snapshots/</url>
<uniqueVersion>false</uniqueVersion> <---- avoid to append current timestamp on uploaded jars.
</snapshotRepository>
</distributionManagement>
12. change default maven repository folder:
${MAVEN_HOME}\conf\settings.xml
------------------------------------------------------------------------------------------
<settings...>
<localRepository>D:\DevTools\apache-maven-2.2.1\repo</localRepository>
</settings>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>local-nexus</id>
<url>http://10.199.130.142:8080/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
13. setting Nexus account:
${MAVEN_HOME}\conf\settings.xml
------------------------------------------------------------------------------------------
<settings...>
<servers>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>mmis@123</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>mmis@123</password>
</server>
</servers>
</settings>
14. run specified testcase in maven-test:
mvn -Dtest=MenuItemFacadeTest test
15. repository list:
<repositories>
<repository>
<id>maven2-repo1</id>
<name>Maven2 Repo 1</name>
<url>http://repo1.maven.org/maven2</url>
</repository>
<repository>
<id>ibiblio</id>
<name>iBiblio Maven2 Repository</name>
<url>http://www.ibiblio.org/maven2</url>
</repository>
<repository>
<id>apache-repo</id>
<name>Apache Repository</name>
<url>http://people.apache.org/repo/m2-snapshot-repository</url>
</repository>
<repository>
<id>compass-project.org</id>
<name>Compass</name>
<url>http://repo.compass-project.org</url>
</repository>
<repository>
<id>java.net</id>
<name>JavaNet</name>
<url>http://download.java.net/maven/2</url>
</repository>
<repository>
<id>http://maven.seasar.org/maven21</id>
<name>http://maven.seasar.org/maven2</name>
<url>http://maven.seasar.org/maven2</url>
</repository>
</repositories>
发表评论
-
Eclipse
2010-12-22 13:29 6341. highlight warning log mes ... -
Java Advance
2010-12-22 13:27 7951. A class with a given name ... -
J2EE EJB OpenEJB
2010-12-22 13:26 12061.Generally speaking the onl ... -
Spring
2010-12-22 13:25 7661. @Autowired vs. setter @A ... -
JPA Toplink
2010-12-22 13:25 15001.persistence.xml --------- ... -
Apache Ant
2010-12-22 13:22 7451. Add additional command li ... -
Trouble Shooting
2010-12-22 13:22 17581. Problem: log4j:WARN D ...
相关推荐
jmeter-maven-plugin, JMeter Maven 插件 #JMeter Maven 插件 提供在构建过程中运行JMeter测试的能力的Maven 插件有关更改信息,请参阅变更日志 。这个插件需要 1.8 或者更高版本,自 2.2.0 #Basic 用法将插
Maven教材.The second command we ran in the previous section Maven lifecycle, which begins with a phase to validate the basic integrity of the project and ends with a phase that involves deploying a ...
java源码剖析基本的Maven示例 这个简单的Maven项目正在导入JaCoCo的覆盖率报告。 有关多模块项目示例,请参见 用法 使用SonarQube Scanner for Maven构建项目,执行所有测试并分析项目(从项目的根目录开始): mvn ...
You should be well versed with Maven and its basic functionalities if you wish to get the most out of this book. Table of Contents Chapter 1: Basic Dependency Management Chapter 2: Dependency ...
Introducing Maven is your quick start-...After reading and using this short book, you'll have an understanding of Maven's dependency management and how to organize basic and multi-module Maven projects.
openmrs-contrib-maven-原型-basicmodule-creation
Maven原型 用于初始化Java项目的Maven原型 如何编译 mvn clean install 如何使用 mvn archetype:generate \ -DarchetypeGroupId=guybrush.maven.... -DarchetypeArtifactId=java-basic \ -DarchetypeVersion=1.0
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
jsmart-basic-archetype Maven原型创建基于JSmart的基本Web项目
java-maven-junit-helloworld “你好,世界!” 使用Maven进行Java编写的示例构建,展示了一些非常简单的测试。 此示例说明: 用编写的单元测试 使用进行单元测试以模拟类并测试System.exit() 用编写的集成测试 ...
Gradle Jinkubator 演示文稿 gradle Jinkubator 演示文稿的材料 - 第一部分: 基本 gradle 项目以及基本 gradle 和 maven 构建脚本之间的比较。 演示文稿可以在
Jpa_Basic Jpa_Basic Inflearn Pracitce 设置Maven H2数据库ORM:JPA IntelliJ 2020.3 JDK 11
基于maven的JSF2的最小系统详情参见:打包mvn清洁包装运行mvn软件包tomcat-deploy
最新的Oracle 数据库 10g 10.2.0.1.0 第 2 版 JDBC 驱动程序 包含: ojdbc14.jar ojdbc14_g.jar ojdbc14dms.jar ojdbc14dms_g.jar
Basic、 Cookie、Header、内外网 统一错误处理、统一Json格式模板 接口请求日志统一处理 接口频次拦截 支持多数据源、主从分离 多Profile支持,Gradle、Spring、应用程序Profile整合 完善的系统监控 热部署 自动生成...
ANT_BASIC 概述了如何使用 ANT 构建编译和打包 Java 应用程序 MAVEN_中级 概述如何使用 maven 构建和编译 scala 应用程序 GRADLE_ADVANCED 高级使用 Gradle 为 Android 构建 JavaFX 应用程序 jfxmobile-plugin
一个多module的maven项目,包含了rabbitmq的basic、workqueue、subsrcibe、direct、topic等经典示例,全部自测通过。
块茎基础松露的基础知识编译并运行用 maven 生成一个可执行的 uberjar: 安装使用默认 JVM 运行: java -jar target/tuber-basic-1.0-SNAPSHOT.jar fizzbuzz.tuber 使用支持 graal 的 JVM 运行:(这会运行程序,但...
弹簧启动基本认证 使用基本身份验证来保护Spring Boot REST API