Tuesday, December 22, 2009

Maven2|常见问题

Maven2常见问题_苹果开发文档

Maven2常见问题
2009-11-23 09:32
1.eclipse的maven插件
http://m2eclipse.sonatype.org/update/

2.本地repository服务器
http://repo2.maven.org/maven2/中所需要的库文件下载到本地repository服务器上供项目组使用,
而不需要每人都从maven2的官方网站去更新所依赖的库文件.
官方站点: http://archiva.apache.org/
下载: http://apache.mirror.phpchina.com/archiva/binaries/apache-archiva-1.1.3-bin.zip
解压: D:\apache-archiva-1.1.3
运行archiva: D:\apache-archiva-1.1.3\bin>archiva console
访问: http://localhost:8080/archiva
设定管理员账号密码,再重新登录即可.
访问http://localhost:8080/archiva/admin/repositories.action即可看到本地repository
http://localhost:8080/archiva/repository/internal/
http://localhost:8080/archiva/repository/snapshots/
将该服务器增加入setting.xml中:

<repositories>
<repository>
<id>localhost</id>
<name>Repository locates at localhost</name>
<url>http://localhost:8080/archiva/repository/internal/</url>
<layout>default</layout>
<snapshotPolicy>always</snapshotPolicy>
</repository>
</repositories>

archiva也提供了上传jar文件到本地repository的功能

另外,Artifactory也提供了类似的功能.

3.设定构建参数
如:编译的JDK版本,字符集等.

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>

4.发布jar文件到本地repository

mvn install:install-file  -Dfile=c:\myfirst.jar -DartifactId=myfirst
-DgroupId=com.mycompany -Dversion=1.0.0
-Dpackaging=jar -DgeneratePom=true -DcreateChecksum=true

5.发布jar文件到repository服务器
首先,到
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
下载plink.exe和pscp.exe

然后,修改setting.xml:

<server>
<id>192.168.1.2</id>
<username>root</username>
<password>root</password>
<configuration>
<sshExecutable>C:/maven2/plink.exe</sshExecutable>
<scpExecutable>C:/maven2/pscp.exe</scpExecutable>
<sshArgs></sshArgs>
</configuration>
</server>

最后,上传到/var/www/html/maven2下面:

mvn deploy:deploy-file -Durl=scpexe://192.168.1.2/var/www/html/maven2
-DrepositoryId=192.168.1.2
-Dfile=c:/myfirst.jar
-DgroupId=com.mycompany
-DartifactId=myfirst
-Dversion=1.0.0
-Dpackaging=jar
-DgeneratePom=true
-DcreateChecksum=true

6. 容器提供依赖jar文件

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>

No comments: