Java maven-archetype-webapp eclipse 问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3042518/
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
maven-archetype-webapp eclipse problem
提问by Jeremy
I'm trying to create a very simple webapp with maven and eclipse, but I'm having no joy at all, in fact the reverse of joy.
我正在尝试使用 maven 和 eclipse 创建一个非常简单的 web 应用程序,但我根本没有快乐,实际上是快乐的反面。
I go to File -> New Project, select Maven Project, and select the maven-archetype-webapp. When I finish the wizard, a webapp structure gets generated but with no 'java' directory under main, just resources and webapp.
我转到 File -> New Project,选择 Maven Project,然后选择 maven-archetype-webapp。当我完成向导时,会生成一个 webapp 结构,但主目录下没有“java”目录,只有资源和 webapp。
So I right click on main and select new Class. The class gets created under resources (?!), and furthermore, there seems to be no compilation of it by java. I can make stupid errors and no syntax highlighting comes up. It's like java isn't recognizing it.
所以我右键单击 main 并选择新类。该类是在资源(?!)下创建的,而且似乎没有由 java 编译它。我可以犯愚蠢的错误并且没有语法高亮出现。就像java没有识别它一样。
Alternatively I have tried creating a new 'java' directory under main where it should be, but still with the same non-existent java symptoms.
或者,我尝试在 main 下创建一个新的“java”目录,但仍然具有相同的不存在的 java 症状。
What gives? This is driving me insane..
是什么赋予了?这让我发疯..
Thanks all!
谢谢大家!
采纳答案by Pascal Thivent
Simply create a java
directory under main
(i.e. src/main/java
) and right-clickon your project and select Maven > Update Project Configuration.
只需java
在main
(ie src/main/java
)下创建一个目录并右键单击您的项目并选择Maven > Update Project Configuration。
回答by Goibniu
There is an option to create a source directory in eclipse. Or you can go to build path under project properties, and add an existing directory as a source directory.
有一个选项可以在 Eclipse 中创建源目录。或者,您可以转到项目属性下的构建路径,并将现有目录添加为源目录。
If you are going to use non-standard directory structure you will have to specify it in maven though
如果要使用非标准目录结构,则必须在 maven 中指定它
回答by McDowell
- Read the m2eclipse WTP mini-howto.
- Check the online Developing with Eclipse and Maven.
- Ensure your settings.xmlis configured in the Eclipse preferences.
- Check the m2eclipse FAQ.
- 阅读 m2eclipse WTP mini-howto。
- 检查在线使用 Eclipse 和 Maven 开发。
- 确保在 Eclipse 首选项中配置了settings.xml。
- 检查m2eclipse 常见问题。
Anything else is likely to be down to the archetype and how you've configured your pom.xml
. The directory structure you describe is identical to the one maven-archetype-webapp
creates on the command line.
其他任何事情都可能取决于原型以及您如何配置pom.xml
. 您描述的目录结构与maven-archetype-webapp
在命令行上创建的目录结构相同。
回答by dira
a webapp structure gets generated but with no 'java' directory under main
生成了一个 webapp 结构,但主目录下没有“java”目录
Create src/main/java on your own.
自己创建 src/main/java 。
furthermore, there seems to be no compilation of it by java. I can make stupid errors and no syntax highlighting comes up. It's like java isn't recognizing it.
此外,似乎没有java编译它。我可以犯愚蠢的错误并且没有语法高亮出现。就像java没有识别它一样。
after creating appropriate dir structure execute the maven command
创建适当的目录结构后,执行 maven 命令
mvn eclipse:eclipse
then refresh the project in eclipse.
然后在eclipse中刷新项目。
-SE
-SE
回答by Linz
Simply create a java directory under main (i.e. src/main/java) and right-click -> Build Path -> Use a Source Folder
只需在 main 下创建一个 java 目录(即 src/main/java)并右键单击 -> Build Path -> Use a Source Folder
回答by Udayan
- By default, When you create a project with maven archetype "maven-archetype-webapp", it doesn't create any java and test folders.
- You can manually add those folders as src/main/java and src/test/java.
- After adding these folders, right click on your project in project explorer, go to maven>update project conf.
- 默认情况下,当您使用 maven 原型“maven-archetype-webapp”创建项目时,它不会创建任何 java 和 test 文件夹。
- 您可以手动将这些文件夹添加为 src/main/java 和 src/test/java。
- 添加这些文件夹后,在项目资源管理器中右键单击您的项目,转到 maven>update project conf。
回答by Miladesnovakaina
in IntelliJ IDEA 13 you must first create "java" folder in main folder then --> go to "open module setting"- for this you can click on project name and press f4- , and set label of "java" folder to "source" .
在 IntelliJ IDEA 13 中,您必须首先在主文件夹中创建“java”文件夹,然后 --> 转到“打开模块设置”-为此您可以单击项目名称并按 f4- ,并将“java”文件夹的标签设置为“来源” 。
回答by Ryan
This is a great article that I read when I was having trouble understanding how to build multiple projects into one using Maven. Specifically, this article explains how to set up a WEB project (war file) to consume an inner standard java project (jar file).
这是一篇很棒的文章,当我无法理解如何使用 Maven 将多个项目构建为一个时,我读到了这篇文章。本文具体讲解了如何搭建一个WEB项目(war文件)来消费一个内部标准的java项目(jar文件)。
If you have a basic understanding of Maven, skip to the sections at the end: How do I build other types of projects? How do I build more than one project at once?
如果您对 Maven 有基本的了解,请跳到最后的部分:如何构建其他类型的项目?如何一次构建多个项目?
http://maven.apache.org/guides/getting-started/index.html#How_do_I_build_other_types_of_projects
http://maven.apache.org/guides/getting-started/index.html#How_do_I_build_other_types_of_projects
If you aren't familiar with Maven yet, check out:
如果您还不熟悉 Maven,请查看:
http://www.mkyong.com/spring/quick-start-maven-spring-example/
http://www.mkyong.com/spring/quick-start-maven-spring-example/
Trust me, mkyong knows what is up!
相信我,mkyong 知道发生了什么!
回答by Lisa
for src/main/java
your project >> properties >> java build path >> source >>
search "Your Project src/main/java (missin)" >>>
对于 src/main/java 您的项目 >> 属性 >> java 构建路径 >> 源 >>
搜索“您的项目 src/main/java (missin)” >>>
edit > folder name >> next >> Inclusion patterns: -----> Add >> src/main/java OK
编辑>文件夹名称>>下一步>>包含模式:----->添加>>src/main/java OK
and if errors still don't disapear
如果错误仍然没有消失
>>> look in Target Runtimes and check your apache in checkbox
回答by Sid Pandey
Here is my solution. It works without any issue.
这是我的解决方案。它可以正常工作。
There could be questions regarding why all this steps are required and i believe they are pretty genuine. But this is one of the ways to make your web application or any other component working on eclipse using Maven from command line.
可能会有关于为什么需要所有这些步骤的问题,我相信它们是非常真实的。但这是使用 Maven从命令行使您的 Web 应用程序或任何其他组件在 Eclipse 上工作的方法之一。
1) Open a command window
1) 打开命令窗口
2) mvn archetype:generate -DgroupId=your package-DartifactId=your Project-DarchetypeArtifactId= your archetype. In my case "maven-archetype-webapp"-DinteractiveMode=false
2) mvn archetype:generate -DgroupId=你的包-DartifactId=你的项目-DarchetypeArtifactId=你的原型。就我而言,“maven-archetype-webapp”-DinteractiveMode=false
3) cd your Project
3) cd你的项目
4) mvn eclipse:eclipse -Dwtpversion=2.0
4) mvn eclipse:eclipse -Dwtpversion=2.0
5) Go to file system. Go to your newly created project. create folders,
a) java under main
b) test under src
c) java and resources under test
5) 进入文件系统。转到您新创建的项目。创建文件夹,a)main
下的java b)src下的test c)java和被测资源
6) mvn eclipse:clean
6) mvn eclipse:clean
7) mvn eclipse:eclipse -Dwtpversion=2.0
7) mvn eclipse:eclipse -Dwtpversion=2.0
8) import your Projectproject in eclipse
8)在eclipse中导入你的Project项目
Thanks, Sid
谢谢,希德