Java Intellij Idea 社区版中的 Tomcat
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22047860/
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
Tomcat in Intellij Idea Community Edition
提问by Viktoriia
Is it possible to run a web application using Tomcat Server in Intellij Idea Community Edition?
是否可以在 Intellij Idea Community Edition 中使用 Tomcat 服务器运行 Web 应用程序?
I tried to find some information about it but haven't achived any success.
我试图找到一些关于它的信息,但没有取得任何成功。
采纳答案by arielduarte
If you are using maven, you can use this command mvn tomcat:run
, but first you add in your pom.xml this structure into build tag, just like this:
如果你使用的是 maven,你可以使用这个命令mvn tomcat:run
,但首先你在你的 pom.xml 中将此结构添加到 build 标记中,就像这样:
<build>
<finalName>mvn-webapp-test</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
回答by Meo
Yes, you can use maven plugin, or simple java program. No need for IDE plugin. See for example Main class from https://devcenter.heroku.com/articles/create-a-java-web-application-using-embedded-tomcat
是的,您可以使用 maven 插件或简单的 java 程序。不需要IDE插件。参见例如来自https://devcenter.heroku.com/articles/create-a-java-web-application-using-embedded-tomcat 的Main 类
回答by vishal gurnaney
For Intellij 14.0.0 the Application server option is available under View > Tools window > Application Server (But if it is enable, i mean if you have any plugin installed)
对于 Intellij 14.0.0,应用程序服务器选项在查看 > 工具窗口 > 应用程序服务器下可用(但如果启用,我的意思是如果您安装了任何插件)
回答by Arthur Carroll
The maven plugin and embedded Tomcat are usable work-arounds (I like second better because you can debug) but actual web server integration is a feature only available in intelij paid editions.
maven 插件和嵌入式 Tomcat 是可用的解决方法(我更喜欢第二个,因为您可以调试)但实际的 Web 服务器集成是一项仅在 intelij 付费版本中可用的功能。
回答by Alex Burdusel
Using Maven, try tomcat7-maven-plugin
:
使用 Maven,尝试tomcat7-maven-plugin
:
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/</path>
<contextFile>src/main/webapp/WEB-INF/config/app-config.xml</contextFile>
<mode>context</mode>
<charset>UTF-8</charset>
<warDirectory>target/${project.artifactId}-${project.version}</warDirectory>
</configuration>
</plugin>
</plugins>
</build>
Run it using tomcat7:run-war
运行它使用 tomcat7:run-war
More goals here
更多进球在这里
回答by javasenior
You can use tomcat plugin with gradle. For more information, you here.
您可以在 gradle 中使用 tomcat 插件。如需更多信息,请点击此处。
apply plugin: 'tomcat'
dependencies {
classpath 'org.gradle.api.plugins:gradle-tomcat-plugin:1.2.4'
}
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
[tomcatRun, tomcatRunWar, tomcatStop]*.stopPort = 8090
[tomcatRun, tomcatRunWar, tomcatStop]*.stopKey = 'stfu'
tomcatRunWar.contextPath = "/$rootProject.name"
tomcatRunWar.ajpPort = 8000
if (checkBeforeRun.toBoolean()) {
tomcatRunWar { dependsOn += ['check'] }
}
回答by user7610
Intellij Community does not offer Java application server integration. Your alternatives are
Intellij 社区不提供 Java 应用程序服务器集成。你的选择是
- buying Intellij licence,
- switching to Eclipse ;)
- installing Smart Tomcatplugin https://plugins.jetbrains.com/plugin/9492
- installing IDEA Jetty Runnerplugin https://plugins.jetbrains.com/plugin/7505
- running the application server from Maven, Gradle, whatever, as outlined in the other answers.
- 购买 Intellij 许可证,
- 切换到 Eclipse ;)
- 安装Smart Tomcat插件https://plugins.jetbrains.com/plugin/9492
- 安装IDEA Jetty Runner插件https://plugins.jetbrains.com/plugin/7505
- 如其他答案中所述,从 Maven、Gradle 等运行应用程序服务器。
I personally installed the Jetty Runner plugin (Jetty is fine for me, I do not need Tomcat) and I am satisfied with this solution. I had to deal with IntelliJ idea - Jetty, report an exception, though.
我个人安装了 Jetty Runner 插件(Jetty 对我来说很好,我不需要 Tomcat)并且我对这个解决方案很满意。不过,我不得不处理IntelliJ 想法 - Jetty,报告异常。
回答by Jay Lin
Yes, its possible and its fairly easy.
是的,这是可能的,而且相当容易。
- Near the run button, from the dropdown, choose "edit configurations..."
- On the left, click the plus, then maven and rename it "Tomcat" on the right side.
- for command line, enter "spring-boot:run"
- Under the runner tab, for 'VM Options', enter "-XX:MaxPermSize=256m -Xms128m -Xmx512m -Djava.awt.headless=true" NOTE: 'use project settings' should be unticked.
- For environment variables enter "env=dev"
- Finally, click Ok.
- 在运行按钮附近,从下拉菜单中选择“编辑配置...”
- 在左侧,单击加号,然后单击 maven 并在右侧将其重命名为“Tomcat”。
- 对于命令行,输入“spring-boot:run”
- 在 runner 选项卡下,对于“VM Options”,输入“-XX:MaxPermSize=256m -Xms128m -Xmx512m -Djava.awt.headless=true” 注意:“使用项目设置”应该取消勾选。
- 对于环境变量,输入“env=dev”
- 最后,单击确定。
When you're ready to press run, if you go to "localhost:8080/< page_name > " you'll see your page.
当您准备好按运行时,如果您转到“localhost:8080/< page_name >”,您将看到您的页面。
My pom.xml file is the same as the Official spring tutorial Serving Web Content with Spring MVC
我的 pom.xml 文件与官方 spring 教程 Serving Web Content with Spring MVC 相同
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>gs-serving-web-content</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
回答by Chandan Kumar
I am using intellij CE to create the WAR, and deploying the war externally using tomcat deployment manager. This works for testing the application however I still couldnt find the way to debug it.
我正在使用 intellij CE 创建 WAR,并使用 tomcat 部署管理器在外部部署战争。这适用于测试应用程序,但我仍然找不到调试它的方法。
- open cmd and current dir to tomcat/bin.
- you can start and stop the server using the batch files start.bat and shutdown.bat.
- Now build your app using mvn goal in intellij.
- Open localhost:8080/ **Your port number may differ.
- Use this tomcat application to deploy the application, If you get the authentication error, you would need to set the credentials under conf/tomcat-users.xml.
- 打开 cmd 和当前目录到 tomcat/bin。
- 您可以使用批处理文件 start.bat 和 shutdown.bat 启动和停止服务器。
- 现在使用 intellij 中的 mvn 目标构建您的应用程序。
- 打开 localhost:8080/ **您的端口号可能会有所不同。
- 使用此 tomcat 应用程序部署应用程序,如果出现身份验证错误,则需要在 conf/tomcat-users.xml 下设置凭据。
回答by Amit Kaneria
Tomcat (Headless) can be integrated with IntelliJ Idea - Community edition.
Tomcat (Headless) 可以与 IntelliJ Idea - 社区版集成。
Step-by-step instructions are as below:
分步说明如下:
Add
tomcatX-maven-plugin
to pom.xml<build> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <path>SampleProject</path> </configuration> </plugin> </plugins> </build>
Add new run configuration as below:
Run >> Edit Configurations >> + >> Maven Parameters tab ... Name :: Tomcat Working Directory :: Project Root Directory Command Line :: tomcat7:run Runner tab ... VM Options :: <user needed options> JRE :: <project needed>
Invoke Tomcat in Run/Debug mode directly from IntelliJ Run >> Run/Debug menu
添加
tomcatX-maven-plugin
到 pom.xml<build> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <path>SampleProject</path> </configuration> </plugin> </plugins> </build>
添加新的运行配置如下:
Run >> Edit Configurations >> + >> Maven Parameters tab ... Name :: Tomcat Working Directory :: Project Root Directory Command Line :: tomcat7:run Runner tab ... VM Options :: <user needed options> JRE :: <project needed>
直接从 IntelliJ Run >> Run/Debug 菜单以 Run/Debug 模式调用 Tomcat
NOTE: Though this is considered a hacking of using using Tomcat integration features of IntelliJ - Enterprise version features, but I would consider this a programmatic way integrating tomcat to the IntelliJ Idea - community edition.
注意:虽然这被认为是使用 IntelliJ 的 Tomcat 集成功能 - 企业版功能的黑客攻击,但我认为这是一种将 tomcat 集成到 IntelliJ Idea - 社区版的编程方式。