简体   繁体   English

我在m2eclipse上构建错误,但在命令行上没有使用maven2 - 我的m2eclipse是否配置错误?

[英]I have build errors with m2eclipse but not with maven2 on the command line - is my m2eclipse misconfigured?

I installed m2eclipse to build a java project in Eclipse. 我安装了m2eclipse来在Eclipse中构建一个java项目。

I imported the project as follows: 我按如下方式导入了项目:

Import->
Maven->
Existing Maven Projects->
Import Maven Projects->
- Select root directory
- Select pom file
- Click Finish

To be sure m2eclipse was actually building the project, I deleted the target directory and made sure it was re-created by m2eclipse and it was. 为了确保m2eclipse实际上正在构建项目,我删除了目标目录,并确保它是由m2eclipse重新创建的,它确实是。 But unlike with the command-line version of maven which built everything perfectly, m2eclipse leaves a large number of build errors in the source code. 但与完全构建所有内容的maven的命令行版本不同,m2eclipse在源代码中留下了大量的构建错误。

Is it possible that I did not configure m2eclipse properly? 有可能我没有正确配置m2eclipse吗? How would I check this? 我该怎么检查?

This is a github link to the project I'm trying to build. 这是我正在尝试构建的项目的github链接 I'm getting the @Override build errors at this line . 我在这一行得到@Override构建错误。 It says "The method createNewToken must override a superclass method". 它说“方法createNewToken必须覆盖超类方法”。

Update: The problem is the same as the one described in 'Must Override a Superclass Method' Errors after importing a project into Eclipse and here is what the accepted answer says: 更新:问题与将项目导入Eclipse后“必须覆盖超类方法”错误中描述的问题相同,这是接受的答案:

Eclipse is defaulting to Java 1.5 and you have classes implementing interface methods (which in Java 1.6 can be annotated with @Override, but in Java 1.5 can only be applied to methods overriding a superclass method). Eclipse默认为Java 1.5,并且您有实现接口方法的类(在Java 1.6中可以使用@Override进行批注,但在Java 1.5中只能应用于覆盖超类方法的方法)。

Changing the compiler level to Java 1.6 would make the problem go away. 将编译器级别更改为Java 1.6会使问题消失。 To do so, modify the compiler plugin configuration: 为此,请修改编译器插件配置:

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

And update the project configuration ( right-click on the project then Maven V Update Project Configuration ) does solve the problem under Eclipse. 并更新项目配置( 右键单击项目,然后Maven V Update Project Configuration )确实解决了Eclipse下的问题。

Or stick with 1.5 but remove the problematic @Override annotations. 或者坚持使用1.5,但删除有问题的@Override注释。

I don't know how Taylor got things working with a Java 1.5 compiler level. 我不知道Taylor是如何使用Java 1.5编译器级别的。 And my guess is that the project wouldn't build on the command line with a JDK 5. 我的猜测是该项目不会在JDK 5的命令行上构建。


But unlike with the command-line version of maven which built everything perfectly, m2eclipse leaves a large number of build errors in the source code. 但与完全构建所有内容的maven的命令行版本不同,m2eclipse在源代码中留下了大量的构建错误。

Hard to say what is happening exactly without seeing those "errors" (are them really errors?). 如果没有看到那些“错误”(他们真的是错误吗?),很难说正是发生了什么。 Please provide some traces. 请提供一些痕迹。

Is it possible that I did not configure m2eclipse properly? 有可能我没有正确配置m2eclipse吗? How would I check this? 我该怎么检查?

One difference is that m2eclipse uses by default a embedded version of Maven 3 which is probably not the same version that you use on the command line. 一个区别是m2eclipse默认使用Maven 3的嵌入式版本,它可能与您在命令行上使用的版本不同。 You can change that through Window V Preferences V Maven V Installation (and add your own installation): 您可以通过Window V Preferences V Maven V Installation (并添加您自己的安装)来更改它:

替代文字

But while I would recommend to use the same version under Eclipse than on the command line, this is very likely not the root cause of the problem, Maven 2 builds should run on Maven 3 without problems. 虽然我建议在Eclipse下使用与命令行相同的版本,但这很可能不是问题的根本原因,Maven 2版本应该在Maven 3上运行而不会出现问题。

I checked out the code. 我检查了代码。 I have exactly the same problem. 我有完全一样的问题。 The code seems to be just broken. 代码似乎刚刚被打破。

Edit: It definitely is. 编辑:肯定是。 Look at the class com.jappstart.service.auth.UserDetailsServiceImpl. 查看类com.jappstart.service.auth.UserDetailsS​​erviceImpl。 It wants to override the method public final UserDetails loadUserByUsername(final String username) but this method doesn't exist in the interface the class implements and is has no superclass. 它想要覆盖方法public final UserDetails loadUserByUsername(final String username)但是这个方法在类实现的接口中不存在,并且没有超类。

Edit: Ok, that doesn't explain why it builds with maven standalone. 编辑:好的,这并不能解释为什么用maven独立构建它。 This also works for me. 这对我也有用。 Very strange. 很奇怪。 It seems that there is something going on with the build that doesn't work with m2eclipse. 看起来构建的东西与m2eclipse不兼容。

Edit: I'm pretty sure the code works because the bytecode is modified by the datanucleus plugin. 编辑:我很确定代码是有效的,因为字节码是由datanucleus插件修改的。 When I run the project as maven build (right-click->Run->maven package) it sucessfully creates the war with m2eclipse. 当我将项目作为maven build(右键单击 - > Run-> maven包)运行时,它成功地用m2eclipse创建了战争。 So my guess is that the problem is with the m2eclipse Maven Builder. 所以我的猜测是m2eclipse Maven Builder的问题。

The override errors will appear if eclipse is configured to use java 1.5 instead of 1.6. 如果将eclipse配置为使用java 1.5而不是1.6,则会出现覆盖错误。 Check the project properties. 检查项目属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM