maven-archetype-webapp Eclipse 问题
我正在尝试使用 Maven 和 Eclipse 创建一个非常简单的 Web 应用程序,但我一点也没有快乐,事实上与快乐相反。
我转到文件 ->新建项目,选择 Maven 项目,然后选择 maven-archetype-webapp。当我完成向导时,会生成一个 webapp 结构,但 main 下没有“java”目录,只有资源和 webapp。
所以我右键单击 main 并选择 new Class。该类是在资源下创建的(?!),而且,java似乎没有对其进行编译。我可能会犯愚蠢的错误,并且不会出现语法突出显示。就好像java不识别它一样。
或者,我尝试在 main 下创建一个新的“java”目录,但仍然具有相同的不存在的 java 症状。
什么给?这让我发疯了..
谢谢大家!
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.
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.
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.
Alternatively I have tried creating a new 'java' directory under main where it should be, but still with the same non-existent java symptoms.
What gives? This is driving me insane..
Thanks all!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(16)
只需在
main
下创建一个java
目录(即src/main/java
),然后在项目上右键单击并选择Maven>更新项目配置。Simply create a
java
directory undermain
(i.e.src/main/java
) and right-click on your project and select Maven > Update Project Configuration.只需在main下创建一个java目录(即src/main/java)并右键->;构建路径->使用源文件夹
Simply create a java directory under main (i.e. src/main/java) and right-click -> Build Path -> Use a Source Folder
其他任何事情都可能取决于原型以及您如何配置
pom.xml
。您描述的目录结构与maven-archetype-webapp
在命令行上创建的目录结构相同。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 onemaven-archetype-webapp
creates on the command line.只需在 src/main/ 下创建名为 java 的新文件夹,
然后右键单击项目并选择 maven->update project
Simply create new folder named java under src/main/
Then right click on project and select maven->update project
有一个选项可以在 eclipse 中创建源目录。或者您可以转到项目属性下的构建路径,然后添加现有目录作为源目录。
如果您要使用非标准目录结构,则必须在 Maven 中指定它
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.
If you are going to use non-standard directory structure you will have to specify it in maven though
请自行创建 src/main/java。
创建适当的目录结构后,执行 maven 命令
,然后在 eclipse 中刷新项目。
-SE
Create src/main/java on your own.
after creating appropriate dir structure execute the maven command
then refresh the project in eclipse.
-SE
对于 src/main/java
您的项目 >>属性>> java构建路径>>来源>>
搜索“您的项目 src/main/java (missin)”>>>
,如果错误仍然没有消失
for src/main/java
your project >> properties >> java build path >> source >>
search "Your Project src/main/java (missin)" >>>
and if errors still don't disapear
右键单击Maven项目->构建路径->配置构建路径
按顺序&导出选项卡,您可以看到类似选择“JRE 系统库”和“Maven 依赖项”复选框的消息
单击“确定”
现在你可以他们
Right click the Maven Project -> Build Path -> Configure Build Path
In Order & Export tab, you can see the message like select 'JRE System Library' and 'Maven Dependencies' checkbox
Click OK
Now you can them
在 IntelliJ IDEA 13 中,您必须首先在主文件夹中创建“java”文件夹,然后 -->转到“打开模块设置” - 为此,您可以单击项目名称并按 f4- ,并将“java”文件夹的标签设置为“source”。
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" .
这是我的解决方案。它工作没有任何问题。
可能会有关于为什么需要所有这些步骤的问题,我相信它们是非常真实的。但这是让您的 Web 应用程序或任何其他组件在 Eclipse 上使用 Maven 从命令行运行的方法之一。
1) 打开命令窗口
2) mvn archetype:generate -DgroupId=您的包 -DartifactId=您的项目 -DarchetypeArtifactId= 您的原型。在我的例子中,“maven-archetype-webapp” -DinteractiveMode=false
3) cd 您的项目
4) mvn eclipse:eclipse -Dwtpversion=2.0
5) 转到文件系统。转到您新创建的项目。创建文件夹,
a) main 下的 java
b) 在src下测试
c) java 和被测试的资源
6) mvn eclipse:clean
7) mvn eclipse:eclipse -Dwtpversion=2.0
8) 在 eclipse 中导入您的项目项目
谢谢,
席德
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.
1) Open a command window
2) mvn archetype:generate -DgroupId=your package -DartifactId=your Project -DarchetypeArtifactId= your archetype. In my case "maven-archetype-webapp" -DinteractiveMode=false
3) cd your Project
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
6) mvn eclipse:clean
7) mvn eclipse:eclipse -Dwtpversion=2.0
8) import your Project project in eclipse
Thanks,
Sid
反过来做。首先创建一个 webapp 项目,然后添加 Maven 框架(在 Intellij 中 - 右键单击项目并选择添加框架支持)。它将为您创建正确的文件夹。
Do it the other way around. First make a webapp project, then add the Maven framework (in Intellij - right click project and select Add framework support). It will create the right folders for you.
即使我将 JRE 系统库添加到当前的 java 版本中,我也遇到了同样的问题,但仍然遇到了同样的问题,然后我删除了 JRE 系统库并再次添加它对我有用
I had the same problem even when i added JRE system library to my current java version but still had same problem then i just deleted JRE system library and added once again it worked for me
只需在 src/main 下添加一个新文件夹“java”即可。将解决问题。因为带有java文件夹的类路径已经在创建的项目的.classpath文件中可用,所以添加java文件夹不会导致任何错误。请参阅 .classpath 文件中的以下条目,它允许添加 java 文件夹。
Just add a new folder "java" under src/main. will solve the problem. Because the classpath with java folder is already available in .classpath file of created project, so adding java folder will not cause any error. see below entry in .classpath file, which allows to add java folder.
以下步骤适用于 eclipse 2020-06
Following steps work in eclipse 2020-06
当JRE系统库指向错误时会发生错误。现在转到“库”选项卡并将 JRE 系统库更改为正确的版本。
error occurs when the JRE System Library is wrongly pointed. Now go to Libraries tab and change the JRE System Library to the correct version.