Maven构建项目文档

bawltherapistΛογισμικό & κατασκευή λογ/κού

13 Δεκ 2013 (πριν από 3 χρόνια και 7 μήνες)

434 εμφανίσεις







M
aven
构建项目文档

一.
M
aven
安装及配置

1.
安装
maven ,
首先确定
jdk
已安装,
maven
最新版本为
3.0.4
,直接解压就
ok
了,之后


maven
的环境变量
M2_HOME
并把其添加到
path

,
设置成
%M2_HOME%
\
bin;

在命令行
通过
mvn

h
查看
maven
是否安装成功

2. maven
设置,修改
maven
下的
settings.xml

D:
\
apache
-
maven
-
3.0.4
\
conf


<servers></servers>
标签中增加
如图


可用于复制的代码如下:

<server>


<id>nexus
-
releases</id>


<username>admin</username>


<password>admin123</password>


</server>


<server>


<id>nexus
-
snapshots</id>


<
username>admin</username>


<password>admin123</password>


</server>



<server>


<id>tomcat</id>


<username>yanlingfxd</username>


<password>111111</password>


</server>



前两

<server>

发布释放版和快照版到
nexus
私服上

I
d

tomcat

server
是为了把
maven
项目发布到
tomcat
服务器上
,
在配置此
server

前需要在
tomcat_home/conf
下的
tomcat_users.xml
中的
<tomcat
-
users><
/
tomcat
-
users>
中配置
如图:


可用于复制的代码如下:


<role rolename="manager"/>

<role rolename="admin"/>

<user
username="yanlingfxd"

password="111111" roles="admin,manager" />


回到
settings.xml


<mirrors>
</mirrors>
中增加


可用于复制的代码如图:


<mirror>


<id>nexus</id>


<mirrorOf>*</mirrorOf>



<url>http://192.168.1.80:8081/nexus/content/groups/public</url>

</mirror>


<profiles>
</profiles>
中增加


可用于复制的代码如下:












<profile>


<id
>nexus</id>


<repositories>


<repository>


<id>central</id>


<url>http://central</url>



<releases><enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots><enabled>true</enabled>
<updatePolicy
>always</updatePolicy>
</snapshots>


</repository>


</repositories>


<pluginRepositories>


<pluginRepository>


<id>central</id>

<url>http://central</url>


<releases><enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<sn
apshots><enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>



</pluginRepository>


</pluginRepositories>

</profile>


<activeProfiles><
/
activeProfiles>
中增加


可用于复制的代码:

<activeProfile>nexus</activeProfile>

到些
maven

settings.xml
配置完成



.
E
clipse

插件
安装及配置


1.
在安装插件之前,首先

eclips
的根目录下,编辑
eclipse.ini


openFile
下增加

-
vm

D:
\
Java
\
jdk1.6.0_19
\
bin
\
javaw.exe

其作用是:在具体的项目中能引用到
jdk
中和
tools.jar


如图所示


然后
·

eclipse
中配置一下
jdk,
点击
window
-

Preference

java
-

Installed JREs


注:设置
vm

-
Xms512M
-
Xmx1024M


还需要安装一下
svn
地址为:
http://subclipse.tigris.org/update_1.8.x

2
.tomcat
插件安装
,
下载
tomcatPluginV33.zip
并解压到
eclipse

plugins
下,重启
tomcat

,tomcat
插 件 就 会 出 现 在 工 具 标 里
,
然 后 点 击
eclipse
中 的
window
-

Preference

Tomcat
-

tomcat home
设置为
tomcat
的根目录即可。

3
.maven
插件安装及配置,点击
help

install new software

点击

add
按钮如输入

http://m2eclipse.sonatype.org/sites/m2e
如图


点击
ok
进行
maven
的插件安装
,
安装完并重启,点击
window
-

Preference

Maven
设置如
图所示



然后点击
User Settings
按钮设置如下


完成
Maven
插件的安装与设置


.
创建和导入
maven
项目


1.
创建
maven
点击
File
-

new

other

Maven

Maven Project


点击
finish maven
项目创建完成


2.
导入
maven
项目


点击
file

import

Maven

Existing Maven Projects

如图


点击
finish
导入完成

四:编译并部暑
maven
项目流程

1.

如果修改
pom.xml
文件
,
修改后选中项目
鼠标
右键

maven
首先执行
Update
Project Configuration,
其次执行:
update Dependencies
最后执行:
Download
Sources

2.

如果需要重新编译,首先选中项目鼠标右键

Run as

Maven clean,
其次选
中项目鼠标
单击
eclipse
导航栏的
project
菜单,点击
clean
完成项目重新编

.

3.

项目部暑
,
首次部暑时
鼠标右键
选中项目

Run as

单击
Maven build
鼠标右

new
生成
new_configuration



修改右上角的
Name
名称
,
点击
Browse Workspace
选中需要发布项目的根目录点
击确定
,
然后在
Goals
里输入
compile

单击
apply ,
点击
close
部暑完成。
然后在
tomcat

server.xml

<host></host>
下增加

<Context

docBase="
项目绝对路径
\
src
\
main
\
webapp" path="" reloadable="true" />

部暑时
鼠标右键
选中项目
Run as

点击
maven build
,完成编译
,
启动
tomcat
后就
可以访问页面


补充说明:

1.

项目的页面引用的
css
样式,
js
及图片用的是相对路径

如:
jrss_web

需要修改
pom.xml
文件
,

<build></build>
下增加如下代码:

<!
--

开发环境

start
--
>


<
outputDirectory
>
src
\
main
\
webapp
\
WEB
-
INF
\
classes
</
outputDirectory
>



<
testOutputDirectory
>
src
\
main
\
webapp
\
WEB
-
INF
\
classes
</
testOutputD
irectory
>




<
plugins
>



<
plugin
>


<
artifactId
>
maven
-
compiler
-
plugin
</
artifactId
>


<
version
>
2.0.2
</
version
>


<
configuration
>


<
source
>
1.6
</
source
>


<
target
>
1.6
</
target
>


<
encoding
>
UTF
-
8
</
encoding
>


</
configuration
>


</
plugin
>



<
plugin
>



<
artifactId
>
maven
-
dependency
-
plugin
</
artifactId
>




<
version
>
2.1
</
version
>




<
executions
>





<
execution
>






<
phase
>
compile
</
phase
>






<
goals
>







<
goal
>
copy
-
dependencies
</
goal
>






</
goals
>






<
configuration
>




<
outputDirectory
>
src
\
main
\
webapp
\
WEB
-
INF
\
lib
</
outputDirectory
>






</
configuration
>





</
execution
>




</
executions
>



</
plugin
>


<
plugin
>




<
artifactId
>
maven
-
clean
-
plugin
</
artifactId
>




<
version
>
2.4.1
</
version
>




<
configuration
>





<
filesets
>






<
fileset
>







<
directory
>
src
\
main
\
webapp
\
WEB
-
INF
\
lib
</
directory
>







<
followSymlinks
>
false
</
followSymlinks
>






</
fileset
>





</
filesets
>




</
configuration
>



</
plugin
>



<!
--

开发环境

end
--
>





注:
遇到如下错误

[ERROR] Failed to execute goal on project jrss_web: Could not resolve
dependencies for project com.jrss:jrss_web:war:1.0.1: Failed to collect
dependencies for [com.jrss:jrss_core:jar:1.0.1 (compile),
org.apache.openejb:javaee
-
api:jar:5.0
-
1 (provided),
java
x.servlet:jstl:jar:1.2 (compile), aopalliance:aopalliance:jar:1.0
(compile), classworlds:classworlds:jar:1.1 (compile),
commons
-
beanutils:commons
-
beanutils:jar:1.8.3 (compile),
commons
-
chain:commons
-
chain:jar:1.2 (compile),
commons
-
collections:commons
-
coll
ections:jar:3.2.1 (compile),
commons
-
digester:commons
-
digester:jar:2.0 (compile),
commons
-
fileupload:commons
-
fileupload:jar:1.2.1 (compile),
commons
-
io:commons
-
io:jar:1.4 (compile), commons
-
codec:commons
-
codec:jar:1.4
(compile), commons
-
lang:commons
-
lang:j
ar:2.5 (compile),
commons
-
logging:commons
-
logging:jar:1.1.1 (compile),
commons
-
validator:commons
-
validator:jar:1.3.1 (compile),
org.freemarker:freemarker:jar:2.3.16 (compile),
net.sf.json
-
lib:json
-
lib:jar:jdk15:2.4 (compile), ognl:ognl:jar:3.0 (compile),
o
ro:oro:jar:2.0.8 (compile), sslext:sslext:jar:1.2
-
0 (compile),
org.apache.struts:struts2
-
json
-
plugin:jar:2.2.1 (compile),
org.apache.struts:struts2
-
convention
-
plugin:jar:2.2.1 (compile),
org.apache.struts:struts2
-
core:jar:2.2.1 (compile),
org.apache.struts
.xwork:xwork
-
core:jar:2.2.1 (compile),
org.apache.struts:struts2
-
spring
-
plugin:jar:2.2.1 (compile),
log4j:log4j:jar:1.2.16 (compile), cglib:cglib
-
nodep:jar:2.2 (compile),
org.aspectj:aspectjweaver:jar:1.6.9 (compile),
javax.persistence:persistence
-
api:jar:
1.0 (compile), cglib:cglib:jar:2.2
(compile), javassist:javassist:jar:3.9.0.GA (compile), antlr:antlr:jar:2.7.6
(compile), org.hibernate:hibernate:jar:3.2.7.ga (compile),
javax.transaction:jta:jar:1.1 (compile), dom4j:dom4j:jar:1.6.1 (compile),
proxool:pro
xool:jar:0.8.3 (compile), com.jcraft:jsch:jar:0.1.49 (compile),
mysql:mysql
-
connector
-
java:jar:5.1.8 (compile), c3p0:c3p0:jar:0.9.1 (compile),
taglibs:standard:jar:1.1.2 (compile), org.slf4j:slf4j
-
log4j12:jar:1.5.8
(compile), velocity:velocity:jar:1.5 (com
pile),
org.apache.httpcomponents:httpclient:jar:4.0.1 (compile),
org.htmlparser:htmlparser:jar:2.1 (compile), jfree:jfreechart:jar:1.0.13
(compile), org.apache.lucene:lucene
-
core:jar:3.0.1 (compile),
org.apache.lucene:lucene
-
highlighter:jar:3.0.0 (compile)
,
org.json:json:jar:20090211 (compile), mmseg4j:mmseg4j
-
all:jar:1.8.2 (compile),
backport
-
util
-
concurrent:backport
-
util
-
concurrent:jar:3.1 (compile),
rome:rome:jar:1.0 (compile), Jama:Jama:jar:1.0 (compile),
org.apache.commons:commons
-
math:jar:2.2 (compile
),
org.slf4j:slf4j
-
api:jar:1.5.8 (compile),
commons
-
httpclient:commons
-
httpclient:jar:3.1 (compile),
junit:junit:jar:4.8.1 (test), opensymphony:quartz
-
all:jar:1.6.3 (compile),
commons
-
net:commons
-
net:jar:2.0 (compile), jxl:jxl:jar:2.6.10 (compile),
net.sou
rceforge.htmlcleaner:htmlcleaner:jar:2.1 (compile),
cn.emay:emayclient:jar:1.0 (compile), org.drools:drools
-
core:jar:5.2.0.Final
(compile), org.drools:drools
-
compiler:jar:5.2.0.Final (compile),
weibo4j:weibo4j:jar:1.0 (compile),
com.danga:java_memcached
-
re
lease:jar:2.6.2 (compile),
org.springframework:spring:jar:2.5.6 (compile),
com.sun.mail:javax.mail:jar:1.4.4 (compile), net.fckeditor:java
-
core:jar:2.6
(compile), net.sf.ehcache:ehcache:jar:1.3.0 (compile), org.jdom:jdom:jar:1.1
(compile)]: Failed to read
artifact descriptor for com.jrss:jrss_core:jar:1.0.1:
Failure to find com.jrss:jrss_parent:pom:1.0.1 in
http://192.168.1.80:8081/nexus/content/groups/public was cached in the local
repository, resolution will not be reattempted until the update interval of

nexus
has elapsed or updates are forced
-
> [Help 1]

[ERROR]

[ERROR] To see the full stack trace of the errors, re
-
run Maven with the
-
e switch.

[ERROR] Re
-
run Maven using the
-
X switch to enable full debug logging.

[ERROR]

[ERROR] For more information a
bout the errors and possible solutions, please
read the following articles:

[ERROR] [Help 1]
http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutio
nExc
eption

请先
install jrss_parent,install jrss_core