Eclipse中如何将导入的Maven子模块转换为Maven项目?
多模块Maven项目导入Eclipse后子模块未被识别为Maven项目问题
问题描述
- 将多模块Maven项目导入Eclipse时,初始子模块未被转换为Maven项目,甚至不具备Java项目特征
- 先后尝试「配置并检测嵌套项目」选项,以及逐个将子模块导入为现有Maven项目,当时Eclipse内的Maven构建显示成功
- 后续发现子模块节点下无「Maven Dependencies」节点,无法查看Maven依赖,仅显示「JRE System Library」节点,确认子模块未被识别为Maven项目
- 执行命令
mvn eclipse:clean eclipse:eclipse后,依赖显示为「Library Dependencies」,仍仅为Java项目;未找到直接转换为Maven项目的选项,考虑备份子模块后从Eclipse删除再重新导入
更新1:成功导入项目的配置文件
.project文件
<?xml version="1.0" encoding="UTF-8"?> <projectDescription> <name>proj_name</name> <comment></comment> <projects> </projects> <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>
.classpath文件
<?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry excluding="path/to/some/file/being/excluded/coming/from/pom/xml/_ServerMessagesTest.java" kind="src" output="Nightly_Build/proj_name" path="src/main/java"> <attributes> <attribute name="optional" value="true"/> <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry> <classpathentry excluding="**" kind="src" output="Nightly_Build/proj_name" path="src/main/resources"> <attributes> <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry> <classpathentry kind="src" output="target/test-classes" path="src/test/java"> <attributes> <attribute name="optional" value="true"/> <attribute name="maven.pomderived" value="true"/> <attribute name="test" value="true"/> </attributes> </classpathentry> <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"> <attributes> <attribute name="maven.pomderived" value="true"/> <attribute name="test" value="true"/> </attributes> </classpathentry> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"> <attributes> <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <attributes> <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry> <classpathentry kind="output" path="Nightly_Build/proj_name"/> </classpath>
备注与疑问
- 成功导入的项目与未成功的是同一项目的不同版本,未成功版本导入时使用了「导入→现有Maven项目→高级→名称模板」选项添加版本后缀修改项目名称
- 曾使用「配置→配置并检测嵌套项目」选项,具体操作细节已记不清
- 通过对比配置文件可推测需要修改的内容,但希望通过Eclipse自带选项完成修改
- Eclipse中是否存在可撤销之前Maven转换操作并重新执行的选项,以确保子模块被识别为标准Maven项目?
内容的提问来源于stack exchange,提问作者tarekahf
相关产品推荐
相关产品推荐

