配置maven的编译版本

我使用maven很不熟练,在eclipse上开发时编译相关的配置都是由eclipse完成的。
而今天需要将maven工程从svn上checkout到linux服务器上,并且由maven编译,就有问题了。
首先,是maven的编译版本不对,默认的是1.3,很多想注解,foreach的用法主有1.5之后才支持。
经过询问得知,由于要部署的web工程是通过eclipse的maven设置向导新创建的,所以pom里的一些配置并没有继承工程组的pom文件里的配置,所以才编译版本过低。在pom文件加上下面代码后则问题解决:
<parent>
    <artifactId>api-t-xxx</artifactId>
    <groupId>com.xxx.t</groupId>
    <version>1.1-SNAPSHOT</version>
</parent>

经研究发现在工程组的pom文件里,无非就是在build标签里多了下面一段代码,所以我觉得(并没实验)在自己创建的maven工程的pom文件里加上它也应该就能解决问题:
<pluginManagement>
	<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-compiler-plugin</artifactId>
			<inherited>true</inherited>
			<configuration>
				<fork>true</fork>
				<meminitial>128m</meminitial>
				<maxmem>768m</maxmem>
			</configuration>
		</plugin>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-release-plugin</artifactId>
			<version>2.1</version>
		</plugin>
	</plugins>
</pluginManagement>
<plugins>
	<plugin>
		<groupId>org.apache.maven.plugins</groupId>
		<artifactId>maven-resources-plugin</artifactId>
		<configuration>
			<encoding>UTF-8</encoding>
		</configuration>
	</plugin>
	<plugin>
		<groupId>org.apache.maven.plugins</groupId>
		<artifactId>maven-compiler-plugin</artifactId>
		<version>2.3.2</version>
		<configuration>
			<compilerArguments>
			<source>1.6</source>
			<target>1.6</target>
			<encoding>UTF-8</encoding>
			</compilerArguments>
		</configuration>
	</plugin>
	<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.0-beta-9</version>
                <configuration>
                <tagBase>http://192.168.105.28:89/svn/t-sohu/web2.0/api-t-sohu-2.0/tags</tagBase>
                </configuration>
        </plugin>
	<plugin>
		<groupId>org.apache.maven.plugins</groupId>
		<artifactId>maven-release-plugin</artifactId>
		<version>2.1</version>
        </plugin>
</plugins>

其次,是maven编译的路径不对,我之前在eclipse上通过build path设置的编译路径跟maven中的配置是半毛钱关系没有,最终加上下面代码才将问题解决:
<build>
    <finalName>upload</finalName>
    <outputDirectory>src/main/webapp/WEB-INF/classes</outputDirectory>
</build>

猜你喜欢

转载自jkhandsome12-163-com.iteye.com/blog/1489724