mvn package command doesn't run successfully a

2019-06-14 02:16发布

问题:

Hi I get a weird error when I run mvn package command from the command line after executing mvn clean command. The error is a compilation failure error.

This is a trace:

annotations are not supported in -source 1.3
06.04.2011 17.06.59 (use -source 5 or higher to enable annotations)
06.04.2011 17.06.59 @Override at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:715)
06.04.2011 17.06.59 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
06.04.2011 17.06.59 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
06.04.2011 17.06.59 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
06.04.2011 17.06.59 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
06.04.2011 17.06.59 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
06.04.2011 17.06.59 at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
06.04.2011 17.06.59 at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
06.04.2011 17.06.59 at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
06.04.2011 17.06.59 at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
06.04.2011 17.06.59 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
06.04.2011 17.06.59 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
06.04.2011 17.06.59 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
06.04.2011 17.06.59 at java.lang.reflect.Method.invoke(Method.java:597)
06.04.2011 17.06.59 at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
06.04.2011 17.06.59 at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
06.04.2011 17.06.59 at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
06.04.2011 17.06.59 at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
06.04.2011 17.06.59 Caused by: org.apache.maven.plugin.CompilationFailureException: Compilation failure
06.04.2011 17.06.59 at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:516)
06.04.2011 17.06.59 at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:114)
06.04.2011 17.06.59 at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
06.04.2011 17.06.59 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)

The strange thing is when I run mvn package command from eclipse IDE /m2eclipse it works perfectly fine (Even after running mvn clean from IDE as well as command prompt). when I run mvn package command from command prompt with the WAR file already built in the target folder by previous mvn package command the command works fine and a war file gets created and gets overwritten on the previously created war file in the target folder. But when I run mvn clean from IDE/Command prompt and then run mvn package from command prompt it gives me the above error and the compilation fails. I want to automate this build process so I need to get this done from command line.

回答1:

Eclipse maven plugin also installs another copy of Maven (core). So, few of things would work differently while running maven command through eclipse VS Command line. To get away from this situation configure your eclipse to use maven installation you're expecting it to use. Window --> Preferences --> Maven--> Installations and change the setting to point to the local copy you've downloaded.



回答2:

The error messages gives the hint:

use -source 5 or higher to enable annotations You have to configure the Compiler plugin to use at least Java 1.5 for compiling.



回答3:

As other posters have started to point out, you're attempting to compile code that is language level 5 (Java 5) compliant (it uses annotations), but your compiler settings are set for language level 1.3.

See Setting the -source and -target of the Java Compiler on the maven-compiler-plugin's page.