Java 如何在 Intellij IDEA 13.1 中使用 Maven 结构创建 Spring MVC 应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24678794/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 14:04:43  来源:igfitidea点击:

How to create Spring MVC application with Maven structure in Intellij IDEA 13.1?

javaspringmavenspring-mvcintellij-idea

提问by Rasool Ghafari

I want to to create new Spring MVCproject in Mavenstructure using Intellij IDEAbut can't do that. actually i want to create project like mkyong.comsamples, like this.

我想使用Intellij IDEAMaven结构中创建新的Spring MVC项目,但不能这样做。实际上我想创建像mkyong.com示例这样的项目,就像这样

NOTE

笔记

I'm new to Intellij IDEAand want to create new project not import from existing project.

我是Intellij IDEA 的新手,想创建不是从现有项目导入的新项目。

采纳答案by geoand

All you need to do is the following.

您需要做的就是以下内容。

Click File-> New Projectand then:

单击File->New Project然后:

First add thisMaven archetype (from the button on top right)

首先添加这个Maven 原型(从右上角的按钮)

enter image description here

在此处输入图片说明

That archetype will help you bootstrap the project by providing some Spring configuration code and must be present in your local Maven repository (directions are provided on how to do that in the link I sent - it's very easy).

该原型将通过提供一些 Spring 配置代码来帮助您引导项目,并且必须存在于您的本地 Maven 存储库中(在我发送的链接中提供了有关如何执行此操作的说明 - 这非常简单)。

After adding the archetype just do like in the following screenshot:

添加原型后,请按照以下屏幕截图进行操作:

enter image description here

在此处输入图片说明

The next screen just asks you for the the GroupId, ArtifactIdand Versionof your project. The following screens are trivial.

下一个屏幕只会询问您项目的GroupId,ArtifactIdVersion。以下屏幕是微不足道的。

That's it!

就是这样!

Note that you can use any archetype you like (although the one I supplied seems to be very much up to date). If you find a better one than the one I supplied, feel free to use it. You can also write your own without too much trouble.

请注意,您可以使用任何您喜欢的原型(尽管我提供的原型似乎是最新的)。如果您发现比我提供的更好的一个,请随意使用它。您也可以自己编写,而不会太麻烦。

回答by dimitrisli

Update as per comment for IntelliJ 15:

根据 IntelliJ 15 的评论更新:

Same instructions apply and here's a view from it:

相同的说明适用,这是它的一个视图:

enter image description here

在此处输入图片说明

Also note that Spring Initializrhas been added in the same New Projectscreen that is becoming the de-facto way of initialising Spring Bootapplications.

另请注意,Spring Initializr已添加到同一个New Project屏幕中,该屏幕正在成为初始化Spring Boot应用程序的事实上的方式。



(initial post)

(初始帖子)

In IntelliJ 13Ultimate Edition it's very simple since the template is built-in:

在 IntelliJ 13Ultimate Edition 中,它非常简单,因为模板是内置的:

File> New Project> Spring> Create project from template> Spring MVC

File> New Project> Spring> Create project from template>Spring MVC

enter image description hereenter image description here

在此处输入图片说明在此处输入图片说明

回答by Alex Weitz

The above suggestions didn't work for me. What I did is Creating MVC projectstraight up with Maven, based on the archtype:

以上建议对我不起作用。我所做的是直接使用 Maven创建 MVC 项目,基于archtype

http://kolorobot.github.io/spring-mvc-quickstart-archetype

http://kolorobot.github.io/spring-mvc-quickstart-archetype

The command is:

命令是:

mvn archetype:generate \
    -DarchetypeGroupId=pl.codeleak \
    -DarchetypeArtifactId=spring-mvc-quickstart \
    -DarchetypeVersion=1.0.0 \
    -DgroupId=my.groupid \
    -DartifactId=my-artifactId \
    -Dversion=version \
    -DarchetypeRepository=http://kolorobot.github.io/spring-mvc-quickstart-archetype

Or, if you want to just Copy-Paste it to shellor cmdin one line:

或者,如果您只想将其复制粘贴到shellcmd在一行中:

mvn archetype:generate -DarchetypeGroupId=pl.codeleak -DarchetypeArtifactId=spring-mvc-quickstart -DarchetypeVersion=1.0.0 -DgroupId=my.groupid -DartifactId=my-artifactId -Dversion=version -DarchetypeRepository=http://kolorobot.github.io/spring-mvc-quickstart-archetype

When DgroupId, DartifactId& Dversionare the groupId, artifactIdand versionof your project.

When DgroupId, DartifactId&DversiongroupId,artifactIdversion你的项目。

It will generate a full working maven project.

它将生成一个完整的 Maven 项目。

The next step is just to import the maven project to IntellijIDEA.

下一步只是将maven项目导入IntellijIDEA。

As for Version 14.1.4:

至于版本 14.1.4:

  1. File-> New-> Project from Existing Sources...and choose the Project you generated.
  2. Check the Import project from external modeland choose Maven.
  3. At this point there will be more configurations, but you can just click Next& Finish.
  1. File-> New->Project from Existing Sources...并选择您生成的项目。
  2. 检查Import project from external model并选择Maven
  3. 此时会有更多的配置,但您可以直接点击Next& Finish

To run the project in your browser you would need to install and configure Apache Tomcat.

要在浏览器中运行该项目,您需要安装和配置Apache Tomcat

IntelliJ and Tomcat.. Howto..?

IntelliJ 和 Tomcat ......如何......?