java 带有 Intellij 的 Maven WebApp - 过程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28742698/
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 WebApp with Intellij - procedure
提问by magikbibi
What is the procedure to make a Java EE WebApp with Maven and Intellij?
使用 Maven 和 Intellij 制作 Java EE WebApp 的过程是什么?
This is what I do:
这就是我所做的:
- File / New / Project
- Project Type : Maven
- Create From archetype : maven-archetype-webapp
- 文件/新建/项目
- 项目类型:Maven
- 从原型创建:maven-archetype-webapp
But when I create a servlet IntelliJ shows a symbol on the servlet:
但是当我创建一个 servlet IntelliJ 在 servlet 上显示一个符号:
This symbol is "Java class located out of the source root. Refer to the section Configuring Content Roots for details"
此符号是“位于源根之外的 Java 类。有关详细信息,请参阅配置内容根部分”
If I launch the project I get an error.
如果我启动项目,我会收到错误消息。
If I mark the "resources" directory as "Sources Root", the project works.
如果我将“resources”目录标记为“Sources Root”,项目就可以运行。
But if I reload Maven (right click / maven / reimport) the resources directory lost the "Source Root" structure.
但是如果我重新加载 Maven(右键单击/maven/reimport),资源目录就会丢失“源根”结构。
I think something is wrong in my procedure.
我认为我的程序有问题。
回答by chrkv
Create a new folder under maincalled java. Then right-click it and select Mark Directory As-> Sources Root. Use this directory for all your java code and everything should work!
在main下创建一个名为java的新文件夹。然后右键单击它并选择Mark Directory As-> Sources Root。将此目录用于所有 Java 代码,一切都应该正常工作!
回答by magikbibi
Thank you to Chrkv !
感谢 Chrkv!
1). Create a new folder under main called java. Then right-click it and select Mark Directory As -> Sources Root
1)。在 main 下创建一个名为 java 的新文件夹。然后右键单击它并选择将目录标记为 -> 源根
2). In Project Structure / Modules / Web enable the checkbox for makes java "Sources Root"
2)。在 Project Structure / Modules / Web 中,启用 make java "Sources Root" 的复选框
Now i can use right click on java / New / Servlet.
现在我可以使用右键单击 java/New/Servlet。
What is the "resources" directory ? (if i cant create servlet here)
什么是“资源”目录?(如果我不能在这里创建 servlet)
Is this the right precedure ?
这是正确的程序吗?
回答by Prabin Upreti
I'd also encountered the same issue and found a solution by replacing the dependency:
我也遇到了同样的问题,并通过替换依赖找到了解决方案:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
by following dependency
通过遵循依赖
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
after adding this and making the java the source root directory as mentioned in above answer, the intellij idea provided the option for creating filters along with web services. I followed the steps from the link : http://www.tugay.biz/2013/10/hello-world-web-application-with-maven.html
添加此内容并将 java 设为上述答案中提到的源根目录后,intellij 想法提供了创建过滤器和 Web 服务的选项。我按照链接中的步骤操作:http: //www.tugay.biz/2013/10/hello-world-web-application-with-maven.html