1.执行创建命令,可以在执行目录下产生一个创建的项目目录
mvn archetype:generate -DarchetypeCatalog=Internal
选择16,输入groupid等,将产生一个新项目
mvn eclipse:eclipse在eclipse中可以通过import可以导入项目,导入成功后,在eclipse的项目中右键弹出菜单,选择Maven>Enable dependency management
3.创建idea项目,参见文章
mvn idea:idea
<profiles> <profile> <id>jdk-1.6</id> <activation> <activeByDefault>true</activeByDefault> <jdk>1.6</jdk> </activation> <properties> <maven.compiler.source>1.6</maven.compiler.source> <maven.compiler.target>1.6</maven.compiler.target> <maven.compiler.compilerVersion>1.6</maven.compiler.compilerVersion> </properties> </profile> </profiles>(2)pom修改
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.5.1</version> <configuration> <source>1.6</source> <target>1.6</target> <encoding>UTF-8</encoding> </configuration> </plugin>
5.cxf产生客户端代码,参见文章
修改pom.xml
<plugin> <groupId>org.apache.cxf</groupId> <artifactId>cxf-codegen-plugin</artifactId> <version>2.6.1</version> <executions> <execution> <id>generatecxfclientsources</id> <phase>generate-sources</phase> <configuration> <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot> <wsdlOptions> <wsdlOption> <wsdl>http://127.0.0.1:8080/getInfoService?wsdl</wsdl> </wsdlOption> </wsdlOptions> </configuration> <goals> <goal>wsdl2java</goal> </goals> </execution> </executions> </plugin>运行
mvn generate-sources
6.跳过单元测试
mvn package -Dmaven.test.skip=true或者
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skip>true</skip> </configuration> </plugin>
7.查看项目依赖情况
mvn dependency:list
mvn dependency:tree
mvn dependency:analyze
8.pom中使用变量
<properties> <test.version>2.6</test.version> </properties> <dependencies> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>${test.version}</version> <scope>provided</scope> </dependency> </dependencies>
依赖范围(Scope) | 对编译classpath有效 | 对测试classpath有效 | 对运行classpath有效 | 例子 |
---|---|---|---|---|
compile | Y | Y | Y | Spring-core |
test | Y | JUnit | ||
provided | Y | Y | Servelet-api | |
runtime | Y | Y | jdbc驱动 | |
system | Y | Y | 本地的,Maven仓库以外的类库文件 |
10.将一个库放到本地repository中
mvn install:install-file -Dpackaging=jar -DgroupId=com.adobe.blazeds -Dversion=4.0.0.14931 -DartifactId=blazeds-common -Dfile=flex-messaging-common.jar
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.7</version> <configuration> <tasks> <ant antfile="build.xml"> <target name="copy-all" /> </ant> <ant antfile="build.xml"> <target name="copy-iroad-flex" /> </ant> <property name="mvn-classpath" refid="maven.compile.classpath"/> <ant antfile="build-jar.xml"> <target name="copy-all" /> </ant> </tasks> </configuration> </plugin>mvn antrun:run
12.添加库到pom.xml文件中
<repositories> <repository> <id>spring-external</id> <name>Spring External Repository</name> <url>http://maven.springframework.org/external</url> </repository> </repositories>