简体   繁体   English

如何让eclipse在我的m2e maven项目中检测到新的Java类?

[英]How can I make eclipse detect my new java class in my m2e maven project?

I have started looking into Maven and wish to build a project from scratch and start writing new classes. 我已经开始研究Maven,并希望从头开始构建一个项目并开始编写新类。

What do I need to do to make eclipse's auto compilation work under a Maven project in the same way as it does in a normal eclipse project? 我需要做些什么来使Eclipse在Maven项目下的自动编译工作与在普通Eclipse项目中的工作相同?

Here is the problem I am facing: 这是我面临的问题:

I have created a new project in eclipse with the m2e plugin. 我已经使用m2e插件在eclipse中创建了一个新项目。

I am using the quickstart archetype, which generates a simple project structure with a main folder and a test folder. 我正在使用quickstart原型,该原型会生成一个带有主文件夹和测试文件夹的简单项目结构。 Initially the main folder contains a java file called App.java (under the package specified during setup). 最初,主文件夹包含一个名为App.java的Java文件(在安装过程中指定的软件包下)。

Now I add a new class in the same package as App.java, say "Other" in the file Other.java, add a public constant to it, and open up App.java for editing. 现在,我在与App.java相同的程序包中添加一个新类,在文件Other.java中说“ Other”,为其添加一个公共常量,然后打开App.java进行编辑。 When I try to reference the class Other, eclipse does not recognise it. 当我尝试引用其他类时,eclipse无法识别它。

I have run Maven compile via eclipse and double checked that the build path output folders are correct, but everything is as it should be. 我已经通过Eclipse运行了Maven编译,并再次检查了构建路径输出文件夹是否正确,但是一切都应该如此。

I have searched through countless tutorials on Maven and Eclipse, but all the ones I have found only talk about setting up the project, not about actually developing under a Maven project. 我搜索了无数有关Maven和Eclipse的教程,但是我发现的所有教程仅谈论设置项目,而不是实际在Maven项目下进行开发。

My Eclipse is standard edition Kepler, and I am using eclipse's embedded maven installation. 我的Eclipse是标准版的开普勒,我正在使用eclipse的嵌入式maven安装。

It seems my workspace may have been corrupted. 看来我的工作区可能已损坏。

I did the following things, one of which will have made the difference. 我做了以下事情,其中​​之一会有所作为。

  1. Delete workspace .metadata folder 删除工作区.metadata文件夹
  2. Set up eclipse to use separate installation of Maven. 将eclipse设置为使用Maven的单独安装。
  3. Create new Maven project with m2e, specifying the location of the project to be different from workspace, eg /dev/maven/ 使用m2e创建新的Maven项目,并指定项目的位置与工作空间不同,例如/ dev / maven /

暂无
暂无

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

相关问题 M2Eclipse:当Maven更新工作区中的项目时,如何避免M2E更改我的类路径 - M2Eclipse: How to avoid M2E to change my classpath while maven updating project in workspace 如何在Eclipse中安装M2E-Maven集成? - How can I install the M2E - Maven Integration in Eclipse? 如何在Eclipse中打开Java项目(使用Maven)? (我使用M2E还是maven-eclipse-plugin) - How do I open a Java project (that uses maven) in Eclipse? (Do I use M2E or maven-eclipse-plugin) 如何使用Luna Service(4.4.1)上的Eclipse m2e将jar文件添加到本地Maven存储库? - How do I add a jar file to my local Maven repository using Eclipse m2e on Luna Service (4.4.1)? 如何在Eclipse中导入Maven EJB项目? (没有m2e) - How do you import a maven EJB project in eclipse? (without m2e) 如何使M2E(Eclipse的Maven集成)知道在哪里找到依赖项? - How to make m2e (maven integration for eclipse) know where to find dependencies? 如何测试Maven / M2e插件在Eclipse中是否正确配置? - how to test if maven/m2e plugin is configured correctly in eclipse? 如何在Eclipse中的m2e / Installed maven中配置工具链插件 - How to configure toolchains plugin in m2e / Installed maven in Eclipse 保存文件时,如何使eclipse m2e构建当前项目以及引用该文件的EAR项目? - On saving a file, how to make eclipse m2e build the current project AND the EAR project that references it? m2e插件-Eclipse-创建了Java类和包。 不被认可为项目的一部分 - m2e plugin - Eclipse - created Java class and package. Not recognized as part of the project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM