简体   繁体   English

将Maven项目导入Eclipse 3.7(m2e 1.0),但是src / main / java未显示为源包

[英]Imported Maven Project into Eclipse 3.7 (m2e 1.0) but src/main/java are not shown as source-package

I have a maven (3.0.4) multi-module build project which works on command line perfect. 我有一个Maven(3.0.4)多模块构建项目,可以在命令行完美环境下工作。

mvn clean package

build successful. 建立成功。

I've tried to import that project into Eclipse 我试图将该项目导入Eclipse

在此处输入图片说明

with m2e 1.0. 使用m2e 1.0。

在此处输入图片说明

but after it's ready i can't see a package folder nor the icon for src-folders (like src/main/java etc). 但准备好后,我看不到软件包文件夹或src文件夹的图标(如src / main / java等)。

在此处输入图片说明

But i would have expected to see something like the following: 但我本来希望看到以下内容:

在此处输入图片说明

Does someone has a hint what problem might be? 有人暗示可能是什么问题吗? Or ideas where to look for? 或在哪里寻找想法?

Update 更新资料

After boiling this down it might be caused by using a Java 1.7. 将其煮沸后,可能是由于使用Java 1.7引起的。 compiler which i have configurate like the following: 我有如下配置的编译器:

 <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>2.5.1</version>
          <configuration>
            <source>${maven.compiler.source}</source>
            <target>${maven.compiler.target}</target>
            <executable>C:/Programme/Java/jdk1.7.0_05/bin/javac</executable>
            <fork>true</fork>
          </configuration>
        </plugin>
        ...

Someone with experience in this area? 有人在这方面有经验吗?

It looks like your project doesn't have a Java nature. 看起来您的项目没有Java性质。 You can change this by right-clicking the project and going to 您可以通过右键单击项目并转到

Properties -> Project Facets -> Convert to faceted form 属性->项目构面->转换为构面形式

From there you can add a Java facet, which should do the job. 从那里可以添加一个Java方面,这应该可以完成工作。 I often find with this sort of thing that it's easier to just edit Eclipse's .project and .classpath files manually (make sure to back them up before you do though!) instead. 我经常发现,通过这种方式手动编辑Eclipse的.project.classpath文件会更容易(一定要先备份它们!)。 You'll probably want to check that your project's .project file includes something like this: 您可能需要检查项目的.project文件是否包含以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    ...
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.m2e.core.maven2Builder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jdt.core.javanature</nature>
        <nature>org.eclipse.m2e.core.maven2Nature</nature>
    </natures>
</projectDescription>

Then make sure your .classpath looks something like this: 然后确保您的.classpath看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    ...
    <classpathentry kind="src" output="target/classes" path="src/main/java"/>
    <classpathentry excluding="**" kind="src" path="src/main/resources"/>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
    <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
    <classpathentry kind="output" path="target/classes"/>
</classpath>

Once you've got all this stuff ready to go, update your project configuration like Michal said and refresh. 准备好所有这些内容之后,请像Michal所说的那样更新项目配置并刷新。

After long fiddling around i've found the problem which solves it for me: 经过长时间的摆弄,我发现了为我解决的问题:

I had a wrong lifecycle mapping for the maven-compiler-plugin (2.5.1) in my configuration which caused the problems. 我的配置中的maven-compiler-plugin(2.5.1)的生命周期映射错误,这导致了问题。 After removing it it works as expected no need to change the facets manually just import the project and it works. 删除后,它可以按预期工作,而无需手动更改构面,只需导入项目即可。

In your eclipse, it might be pointing to JRE instead of JDK . 在您的日食中,它可能指向JRE而不是JDK Go to window->preference->java->Installed JRE . 转到window->preference->java->Installed JRE Add JDK here, and set it to default. 在此处添加JDK,并将其设置为默认值。 You may need to restart eclipse. 您可能需要重新启动Eclipse。

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

相关问题 Eclipse 3.7(indigo SR2)m2e(1.1)导入Maven不会添加已生成源的源文件夹 - Eclipse 3.7 (indigo SR2) m2e (1.1) import Maven will not add source folders of generated sources m2e阴影蚀“项目主要工件不存在” - m2e shade eclipse “project main artifact does not exist” Eclipse中的Spring Starter项目 - 无法使用Maven:M2E - Spring Starter Project in Eclipse — Can not use Maven: M2E M2E(日食)转换为Maven项目后抛出错误 - m2e (eclipse) Throwing error after converting to a maven project 如何让eclipse在我的m2e maven项目中检测到新的Java类? - How can I make eclipse detect my new java class in my m2e maven project? m2e插件-Eclipse-创建了Java类和包。 不被认可为项目的一部分 - m2e plugin - Eclipse - created Java class and package. Not recognized as part of the project 如何在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) Maven for Eclipse(M2E)安装错误 - Maven for Eclipse (M2E) Installation error M2E 并让 maven 生成源文件夹作为 Eclipse 源文件夹 - M2E and having maven generated source folders as eclipse source folders Eclipse 3.7 / Indigo m2e WTP集成依赖问题 - Eclipse 3.7/Indigo m2e WTP integration dependency issue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM