m2eclipse 将 JDK 合规性设置为 1.4

发布于 2024-09-05 16:08:30 字数 178 浏览 8 评论 0 原文

使用eclipse 3.5,当我创建一个新的maven项目时,m2eclipse自动将J2SE1.4添加到库中,并将编译器合规级别添加到1.4(项目属性> Java编译器)。 我的 JRE 系统库是 1.6,我的默认编译器合规级别是 1.6。我什至没有安装1.4。 我可以让 m2eclipse 使用我的默认设置并阻止它修改项目设置吗?

Using eclipse 3.5, when I create a new maven project, m2eclipse automatically adds J2SE1.4 to libraries and Compiler Compliance Level to 1.4 (Project properties > Java Compiler).
My JRE system library is 1.6 and my default compiler compliance level is 1.6. I don't even have 1.4 installed.
Can I make m2eclipse use my default settings and prevent it from modifying project settings?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

云柯 2024-09-12 16:08:31

它应该遵循 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>

即使,如 在此线程中提到,它不适用于方面-j)

这个线程提醒我们 Eclipse 中的 m2eclipse 和 Maven 脚本之间的区别:

值得一提的是,这仅适用于 m2eclipse 根据 pom.xml 中的配置配置 Eclipse 工具(例如 JDT、AJDT 和 WTP)时的“开发模式”。这是您通常编码和调试应用程序、运行单元测试(使用“运行为.../JUnit 测试”)或在 Web 应用程序服务器上运行(运行为.../服务器应用程序)的方式。

但是,如果您使用 Run as.../Maven build...,或者从 Run/Debug 菜单创建相应的启动配置,那么您可以选择用于启动 Maven 的 JVM,并且所有编译器配置都将受到尊重以同样的方式在命令行中受到尊重。

所以:

  <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 不(也不能)使用外部 java 编译器,因此它只会忽略这些配置参数。 m2 仅考虑源/目标 maven-compiler-plugin 参数。

It should follow the maven-compiler-plugin configuration:

<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>

(even if, as mentioned in this thread, it won't work for aspect-j)

This thread reminds us about the difference between m2eclipse within eclipse, and a maven script:

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.

So:

  <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.

漆黑的白昼 2024-09-12 16:08:31

JDK 合规性级别是从 Maven 项目派生的,而不是相反。换句话说,您需要配置maven编译器插件以符合1.6级别,然后m2eclipse将在Eclipse下导出适当的设置:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>2.0.2</version>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
  </configuration>
</plugin>

pom.xml是master,而不是m2eclipse。

The JDK compliance level is derived from the maven project, not the other way around. In other words, you need to configure the maven compiler plugin for 1.6 level compliance and then m2eclipse will derive the appropriate settings under Eclipse:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>2.0.2</version>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
  </configuration>
</plugin>

The pom.xml is the master, not m2eclipse.

指尖上得阳光 2024-09-12 16:08:31

总之,我对项目执行了 mvn eclipse:eclipse ,并在 Eclipse 中对项目进行了 F5 刷新,这正确配置了 Java 合规性设置。

我的设置如下。使用开普勒。 Java 1.7 在 Eclipse 的首选项中配置为默认值(正如已经提到的,似乎无论如何都会被忽略,以尊重 pom.xml 中找到的任何内容)。我将一堆 Maven 项目导入到 Eclipse 中。所有这些都显示为 Java 合规级别 1.4,甚至项目的构建路径也列出了 Java 1.4 运行时。我通过在命令行上请求有效的 pom 来仔细检查 1.7 是否在 pom.xml 中正确指定,以确认 pom 中存在且正确的设置:

mvn help:effective-pom -Doutput=eff.xml

这表明存在正确的设置:

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.5.1</version>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
        <fork>true</fork>
    </configuration>
</plugin>

猜测问题出在导入部分m2e插件,Eclipse中显示的版本是:
1.4.0.20130601-0317

In summary I did an mvn eclipse:eclipse on the project and an F5 refresh of the project in Eclipse and this configured the Java compliance setting correctly.

My set-up as follows. Using Kepler. Java 1.7 configured as default in preferences in Eclipse (as mentioned already, seems to be ignored anyway in deference to whatever is found in the pom.xml). I imported a bunch of Maven projects into Eclipse. All showed up as Java compliance level 1.4 and even the build path of the projects lists the Java 1.4 runtime. I double checked 1.7 is correctly specified in the pom.xml by requesting the effective pom on the command line to confirm the setting is present and correct in the pom:

mvn help:effective-pom -Doutput=eff.xml

This showed the correct setting was present:

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.5.1</version>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
        <fork>true</fork>
    </configuration>
</plugin>

Guessing the problem is with the import part of the m2e plugin, version showing in Eclipse is:
1.4.0.20130601-0317

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文