对于eclipse新建maven工程需要注意的地方。

时间:2022-05-21 23:50:09

新建项目的时候,如果想配置默认的maven的jre为1.6或者别的。

http://hi.baidu.com/hi_hi/item/765ec8bbc49880d384dd79d1

1.cmd命令建立web项目:mvn archetype:generate -DgroupId=biz.yunduo -DartifactId=dts -DpackageName=dts -DarchetypeArtifactId=maven-archetype-webapp

2.如下图,eclipse3.6 For javaEE下有个警告,意思是项目Build path指定的jre是j2se1.5但是找不到与此版本严格匹配的jre

对于eclipse新建maven工程需要注意的地方。

3.纠结了好长时间,不如看看maven的配置文件吧。打开%maven_home%\conf\setting.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>

以后再使用maven生成项目默认编译级别就是1.6的了

4.如果你有特别的需要,比如不同的项目使用的jre不同那么可以在项目的pom.xml里添加如下配置:

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>

上面的是默认的。如果,想修改已经创建好的maven项目的jre和Web Module Version要修改项目Location下面的org.eclipse.wst.common.project.facet.core.xml

<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="jst.web" version="3.0"/>
<installed facet="wst.jsdt.web" version="1.0"/>
<installed facet="jst.jaxrs" version="1.1"/>
<installed facet="java" version="1.7"/>
</faceted-project>

同时,要修改web.xml里的web-app内容

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd "
version="3.0">
<display-name>Archetype Created Web Application</display-name>
</web-app>

关于遇到The import javax.servlet.annotation cannot be resolved的问题,是因为支持annotation需要下面的版本javax.servlet

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>