maven2编译报错

一.错误信息

今天优化了一个pom文件,结果出现下面的编译错误:


/home/yangbolin/workspace/decompile/decompile_shared/src/main/java/com/alibaba/decompile/frame/info/ObjectVariableInfo.java:[30,5] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
    @Override

/home/yangbolin/workspace/decompile/decompile_shared/src/main/java/com/alibaba/decompile/client/DecompileClient.java:[55,12] generics are not supported in -source 1.3
(use -source 5 or higher to enable generics)
        List<ByteCode> byteCodeList = readByteCodeFile.parse();

/home/yangbolin/workspace/decompile/decompile_shared/src/main/java/com/alibaba/decompile/common/DeprecatedInfoParser.java:[29,5] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
    @Override

/home/yangbolin/workspace/decompile/decompile_shared/src/main/java/com/alibaba/decompile/frame/info/UninitializedThisVariableInfo.java:[19,5] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
    @Override

/home/yangbolin/workspace/decompile/decompile_shared/src/main/java/com/alibaba/decompile/frame/parser/impl/TopVariableInfoParser.java:[23,5] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
    @Override

/home/yangbolin/workspace/decompile/decompile_shared/src/main/java/com/alibaba/decompile/handler/impl/ClassHandler.java:[27,5] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
    @Override

/home/yangbolin/workspace/decompile/decompile_shared/src/main/java/com/alibaba/decompile/attribute/info/CodeInfo.java:[57,16] generics are not supported in -source 1.3
(use -source 5 or higher to enable generics)
    private List<AttributeInfo>   attributeInfoList   = new ArrayList<AttributeInfo>();


[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.BuildFailureException: Compilation failure
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:715)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.CompilationFailureException: Compilation failure
at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:516)
at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:114)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
... 17 more



从错误发现是由于JDK的版本过低导致不支持注解和泛型,就是说在使用maven进行编译的时候,如果不指定JDK版本,默认使用的是1.3,1.3不支持注解和泛型,如果程序中有注解和泛型,那就悲剧,编译不过。

二.解决方法

知道原因所在之后,那就很好解决问题了,我们只需要在pom文件中指定JDK的版本就OK了,增加下面这样一个plugin

<plugins>  
			<!--要是没有这个插件的话,maven就会出现编译错误,说不支持annotations-->
			<plugin>  
			  <groupId>org.apache.maven.plugins</groupId>  
			  <artifactId>maven-compiler-plugin</artifactId>  
			  <configuration>  
				<source>1.6</source>  
				<target>1.6</target>  
				<encoding>GBK</encoding>  
			  </configuration>  
			</plugin>  
</plugins>

三.感想

不知道maven为何提供插件而不自己去检测一下机器上JDK的版本呢?

你可能感兴趣的:(企业应用)