`

设置JAVA编译程序级别,Maven编译插件(翻译)--(2)

阅读更多

通过Maven compiler Plugin选项可以设置javac的编译选项

Maven Compiler Plugin

The Compiler Plugin is used to compile the sources of your project. The default compiler is javac and is used to compile Java sources. Also note that at present the default source setting is 1.5 and the default target setting is 1.5, independently of the JDK you run Maven with. If you want to change these defaults, you should set source and target as described in Setting the -source and -target of the Java Compiler.

Other compilers than javac can be used and work has already started on AspectJ, .NET, and C#.

This Compiler Plugin corresponds to Maven 1.x's Java Plugin.

 

Maven 编译插件是用于编译项目源程序。缺省的编译器是javac来编译java文件。注意当前的插件缺省的source和target都是1.5.

 

  •  将程序按java1.6编译

参见链接http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html

Setting the -source and -target of the Java Compiler

如下设置,就可以将程序编译为1.6的

注意只要修改maven-compiler-plugin的选项,
如果要指定源码的编码方式在configuration中增加<encoding>UTF-8</encoding>就变为UTF-8编码方式。
同理,如果要设置其他参数,可参见JAVAC的编译选项http://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html
<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.5</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
    </plugins>
    [...]
  </build>
  [...]
</project>
 
这个可以和ANT比较,还是不如ANT清晰,还是ANT适合编译
 
	<target name="build" depends="init">
		<!--编译 -->
		<javac 	
			srcdir="${src.dir}" 
			destdir="${build.classes}" 
			source="${javac.source}"
			target="${javac.jvm-target}" 
			debuglevel="${debuglevel}"
			includeJavaRuntime="yes" 
			includeAntRuntime="no"
			listfiles="yes"
			encoding="${encoding}"
			debug="${javac.debug}" 
			deprecation="${javac.deprecation}" 
			optimize="${javac.optimize}">
			
			<classpath refid="classpath" />
			<compilerarg value="-Xlint:unchecked"/>

		</javac>
	</target>
<compilerArgument>-Xlint:unchecked</compilerArgument>
 

常见遇到的maven问题

当使用maven dependency:tree命令时:出现错误,搜索时,有如下答案(颁布不兼容性):

tree: org/sonatype/aether/version/VersionConstraint
https://cwiki.apache.org/confluence/display/MAVEN/AetherClassNotFound 写道

org.apache.maven.plugins

maven-shade-plugin

shade

Maven Shade Plugin

2.1

MSHADE-143

 

 

org.apache.maven.plugins

maven-dependency-plugin

tree

Maven Dependency Plugin

2.8

MDEP-407

分享到:
评论
1 楼 g_man1990 2016-06-16  
maven clean后无法生成。class文件

相关推荐

Global site tag (gtag.js) - Google Analytics