使用eclipse 3.5,当我创建一个新的maven项目时,m2eclipse会自动将J2SE1.4添加到库中,并将Compiler Compliance Level添加到1.4(项目属性> Java Compiler)。
我的JRE系统库是1.6,默认的编译器遵从性级别是1.6。我什至没有安装1.4。
我可以使m2eclipse使用我的默认设置并阻止它修改项目设置吗?
最佳答案
它应遵循 maven-compiler-plugin
配置:
<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>
(即使作为mentioned in this thread,也不适用于aspect-j)This thread让我们想起了eclipse中的m2eclipse和maven脚本之间的区别:
One thing worth to mention that this only applies to "the development mode" when m2eclipse is configuring Eclipse tools such as JDT, AJDT and WTP according to the configuration from pom.xml. This is how you normally code and debug your application, run unit tests (with Run as... / JUnit test) or run on web app server (Run as... / Server app).
However if you use Run as... / Maven build..., or create corresponding launch config from the Run/Debug menu, then you can select JVM that is used to launch Maven and all your compiler configuration will be respected in the same way it is respected in the command line.
所以:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable><!-- path-to-javac --></executable>
<compilerVersion>1.3</compilerVersion>
</configuration>
</plugin>
</plugins>
m2e does not (and cannot) use external java compiler, so it will just ignore these configuration parameters. m2 only considers source/target maven-compiler-plugin parameters.
关于eclipse - m2eclipse将JDK兼容性设置为1.4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3032628/