maven一些基本操作

1.执行创建命令,可以在执行目录下产生一个创建的项目目录
mvn archetype:generate -DarchetypeCatalog=Internal  

选择16,输入groupid等,将产生一个新项目
2.创建eclipse项目
mvn eclipse:eclipse  

在eclipse中可以通过import可以导入项目,导入成功后,在eclipse的项目中右键弹出菜单,选择Maven>Enable dependency management
3.创建idea项目,参见[url]http://maven.apache.org/plugins/maven-idea-plugin/[/url]
mvn idea:idea  

4.修改jdk版本
(1)全局修改conf\settings.xml
<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产生客户端代码,参见文章[url]http://cxf.apache.org/docs/maven-cxf-codegen-plugin-wsdl-to-java.html[/url]
修改pom.xml
[url][/url]
			<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>


9.dependency依赖范围
依赖范围(Scope),对编译classpath有效,对测试classpath有效,对运行classpath有效,例子
compile Y Y Y Spring-core
test Y JUnit[/list]
provided Y Y Servelet-api
runtime Y Y jdbc驱动[/list]
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


11.调用ant插件
<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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值