eclipse 无法识别包
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4164597/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
eclipse does not recognize package
提问by user446249
(HELIOS Eclipse, m2eclipse is installed from the update site)
(HELIOS Eclipse,从更新站点安装m2eclipse)
I am creating a new web application: File->New->Other->Maven->Maven Project, Next, Next, then selected maven-archetype-webapp, added a Group Id and Artifact Id. Now in the newly created project I want to add a new java package: right click on , new -> package. Inserted package name and click on finish.
我正在创建一个新的 Web 应用程序:File->New->Other->Maven->Maven Project,Next,Next,然后选择 maven-archetype-webapp,添加了 Group Id 和 Artifact Id。现在在新创建的项目中,我想添加一个新的 java 包:右键单击 ,新建 -> 包。插入包名并点击完成。
And I'm getting a new folder. Eclipse does not recognize this as a package.
我得到了一个新文件夹。Eclipse 不会将此识别为包。
What should I do to make Eclipse recognize that folder as a package?
我应该怎么做才能让 Eclipse 将该文件夹识别为包?
Many tia,
许多 tia,
DHR
人力资源部
回答by Pascal Thivent
The maven-archetype-webapp
does not generate a src/main/java
folder by default and if you want to add Java sources in your webapp, you need to create src/main/java
yourself.
在maven-archetype-webapp
不生成src/main/java
默认文件夹,如果你想添加的Java源代码在你的web应用,你需要创建src/main/java
自己。
Once this directory has been created, right-clickon your project and then use Maven > Update Project Configurationand it will get added as source directory. Then you'll be able to add sources.
创建此目录后,右键单击您的项目,然后使用 Maven > 更新项目配置,它将被添加为源目录。然后你就可以添加源了。
Last thing, either use the maven-eclipse-plugin oruse m2eclipse, not both, they are mutually exclusive.
最后一件事,要么使用 maven-eclipse-plugin要么使用 m2eclipse,不能同时使用,它们是相互排斥的。
回答by greuze
It should work. You can mark the folder containing the package as "source folder" in eclipse, but only as a fast solution...
它应该工作。您可以在 eclipse 中将包含包的文件夹标记为“源文件夹”,但只能作为一种快速解决方案......
I usually work with eclipse wihout m2eclipse, and I run mvn eclipse:eclipse
to generate the eclipse project. Maybe you can manually fix this running the command now (from eclipse with the plugin or from mvn directly).
我通常在没有m2eclipse的情况下使用eclipse,然后运行mvn eclipse:eclipse
生成eclipse项目。也许您现在可以手动修复此运行命令(从带有插件的 eclipse 或直接从 mvn)。