Java IntelliJ IDEA 13.0.3 和 Tomcat 8.0.9。无法让它工作

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

IntelliJ IDEA 13.0.3 and Tomcat 8.0.9. Cant get it to work

javatomcatintellij-idea

提问by Weson

I'm trying to deploy a Java web application running on Tomcat. I got the book

我正在尝试部署在 Tomcat 上运行的 Java Web 应用程序。我拿到书了

Professional Java for Web Applications: Featuring Websockets, Spring Framework, JPA Hibernate, and Spring Security

用于 Web 应用程序的专业 Java:具有 Websockets、Spring 框架、JPA Hibernate 和 Spring Security

and I've done everything said to get IntelliJ IDEA 13 work together with Tomcat 8.0.9. I've tested the server container manually and it works great, even deploying .war files works great. However when i move on to start/debug a web application - in this case the first example form the book - from IntelliJ the application wont start. The output in the Tomcat Log doesn't say much.

为了让 IntelliJ IDEA 13 与 Tomcat 8.0.9 一起工作,我已经做了一切。我已经手动测试了服务器容器,它运行良好,甚至部署 .war 文件也运行良好。但是,当我继续启动/调试 Web 应用程序时(在本例中是本书的第一个示例),来自 IntelliJ 的应用程序将无法启动。Tomcat Log 中的输出并没有说太多。

Server output tells me this:

服务器输出告诉我:

Connected to server
[2014-08-08 09:17:35,075] Artifact Sample-Debug-IntelliJ:war exploded: Artifact is      being deployed, please wait...
[2014-08-08 09:17:35,097] Artifact Sample-Debug-IntelliJ:war exploded: Error during  artifact deployment. See server log for details.
[2014-08-08 09:17:35,098] Artifact Sample-Debug-IntelliJ:war exploded: com.intellij.javaee.oss.admin.jmx.JmxAdminException: com.intellij.execution.ExecutionException: L:\java-dev\java_web_apps_chapter_code81118656464 Full Code\Chapter 02\Sample-Debug-    IntelliJ\target\sample-debug-intellij-1.0.0.SNAPSHOT not found for the web module.
08-Aug-2014 21:17:44.671 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory L:\java-dev\apache-tomcat-8.0.9\webapps\manager
08-Aug-2014 21:17:44.939 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory L:\java-dev\apache-tomcat-8.0.9\webapps\manager has finished in 268 ms

Tomcat Catalina Log output this:

Tomcat Catalina 日志输出如下:

08-Aug-2014 22:56:35.843 INFO [main] org.apache.catalina.core.AprLifecycleListener.init Loaded APR based Apache Tomcat Native library 1.1.30 using APR version 1.4.8.
08-Aug-2014 22:56:35.846 INFO [main] org.apache.catalina.core.AprLifecycleListener.init APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
08-Aug-2014 22:56:36.652 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized (OpenSSL 1.0.1g 7 Apr 2014)
08-Aug-2014 22:56:36.738 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-apr-8080"]
08-Aug-2014 22:56:36.746 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-apr-8009"]
08-Aug-2014 22:56:36.747 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 1060 ms
08-Aug-2014 22:56:36.771 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
08-Aug-2014 22:56:36.771 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.9
08-Aug-2014 22:56:36.778 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-apr-8080"]
08-Aug-2014 22:56:36.784 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-apr-8009"]
08-Aug-2014 22:56:36.785 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 38 ms
08-Aug-2014 22:56:46.785 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory L:\java-dev\apache-tomcat-8.0.9\webapps\manager
08-Aug-2014 22:56:47.035 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory L:\java-dev\apache-tomcat-8.0.9\webapps\manager has finished in 251 ms

I've tried on both Windows and OSX and it's the same story on both with the exact same error.

我在 Windows 和 OSX 上都尝试过,两者都是相同的故事,但有完全相同的错误。

When i access http://localhost:8080/i can see that the server is up and running. However, the application isn't deployed.

当我访问时,http://localhost:8080/我可以看到服务器已启动并正在运行。但是,未部署应用程序。

Anyone experiencing the same error as me and/or know a solution?

有人遇到与我相同的错误和/或知道解决方案吗?

I'm running IntelliJ IDEA 13.0.3, Java 1.8.0_11 and Tomcat 8.0.9.

我正在运行 IntelliJ IDEA 13.0.3、Java 1.8.0_11 和 Tomcat 8.0.9。

EDIT: I've also tried with IntelliJ IDEA 13.1.4. Didn't make any difference.

编辑:我也尝试过 IntelliJ IDEA 13.1.4。没有任何区别。



Steps taken

采取的步骤

  1. Downloaded Java 1.8.0_11, installed it and added it to environment variables.
  2. Downloaded Tomcat, unpacked it and made the following changes to it (step 2-4); In conf/tomcat-users.xmli added this user:

    <user username="admin" password="admin" roles="manager-gui,admin-gui" />
    
  3. In conf/web.xmli added the code below beneath the org.apache.jasper.servlet.jspServletelement

    <init-param>
        <param-name>compilerSourceVM</param-name>
        <param-value>1.8</param-value>
    </init-param>
    <init-param>
        <param-name>compilerTargetVM</param-name>
        <param-value>1.8</param-value>
    </init-param>
    <init-param> 
        <param-name>compiler</param-name>
        <param-value>modern</param-value>
    </init-param>
    
  4. Downloaded apache-ant and added a setenv.batfile in the apache-tomcat/bindirectory with the following script

    export CLASSPATH=L:/java-dev/jdk8/lib/tools.jar:L:/java-dev/apache-ant/lib/ant.jar:L:/java-dev/apache-ant/lib/ant-launcher.jar 
    
  5. Started IntelliJ and added the Tomcat application server.

  6. Then i imported the project and set it to use the Tomcat server that I just added.

  1. 下载 Java 1.8.0_11,安装它并将其添加到环境变量中。
  2. 下载Tomcat,解压并进行如下修改(步骤2-4);在conf/tomcat-users.xml我添加了这个用户:

    <user username="admin" password="admin" roles="manager-gui,admin-gui" />
    
  3. conf/web.xml我在org.apache.jasper.servlet.jspServlet元素下方添加了下面的代码

    <init-param>
        <param-name>compilerSourceVM</param-name>
        <param-value>1.8</param-value>
    </init-param>
    <init-param>
        <param-name>compilerTargetVM</param-name>
        <param-value>1.8</param-value>
    </init-param>
    <init-param> 
        <param-name>compiler</param-name>
        <param-value>modern</param-value>
    </init-param>
    
  4. 下载 apache-ant 并setenv.batapache-tomcat/bin目录中添加一个文件,脚本如下

    export CLASSPATH=L:/java-dev/jdk8/lib/tools.jar:L:/java-dev/apache-ant/lib/ant.jar:L:/java-dev/apache-ant/lib/ant-launcher.jar 
    
  5. 启动 IntelliJ 并添加 Tomcat 应用程序服务器。

  6. 然后我导入了该项目并将其设置为使用我刚刚添加的 Tomcat 服务器。

UPDATE: 2014-08-09 16:22

更新:2014-08-09 16:22

I tried to deploy a JavaEE web application that IntelliJ created itself, and that worked right away. Seems like it's something wrong with the source code that the book references.

我尝试部署一个 IntelliJ 自己创建的 JavaEE Web 应用程序,并且立即生效。这本书引用的源代码似乎有问题。

回答by proactive-e

Open "Debug Configuration" in IntelliJ IDEA and make sure that "Deploy applications configured in Tomcat" checkbox is checked as it shown on the screenshot

在 IntelliJ IDEA 中打开“调试配置”并确保选中“部署在 Tomcat 中配置的应用程序”复选框,如屏幕截图所示

回答by Martin Mecera

I had similar problem. The problem was in artifact configuration in Run/Debug Configurations. I had to remove the project artifact and readd it. The important thing is to choose Web Application: Exploded, From Modules...

我有类似的问题。问题出在运行/调试配置中的工件配置中。我不得不删除项目工件并阅读它。重要的是选择 Web Application: Exploded, From Modules...

You can read my blog postthat contains screenshots about this issue.

您可以阅读我的博客文章,其中包含有关此问题的屏幕截图。

回答by Hoque MD Zahidul

For me it worked with:

对我来说,它适用于:

File >Project Structure >Artifacts In the Output Layout on the right side >"Available Elements?"

文件>项目结构>右侧输出布局中的工件>“可用元素?”

right click on the available libraries ( for me it was "Spring MVC-4.2.4.RELEASE")

右键单击可用的库(对我来说是“Spring MVC-4.2.4.RELEASE”)

Put into Lib ( actually click on the fix warning button )

放入 Lib(实际上是点击修复警告按钮)

And it worked.

它奏效了。

回答by Martin Pfeffer

  1. open the artifact config dialog (artifact > edit...)
  2. check 'Show contents of elements' in the dialogs bottom section
  3. highlight the 'WEB-INF' directory
  4. right click on the library container (on the right pane)
  5. select from context menu 'put into /WEB-INF/lib'
  6. the lib folder is added in the output layout

  7. rebuild artifact

  8. restart webserver
  1. 打开工件配置对话框(工件 > 编辑...)
  2. 选中对话框底部的“显示元素内容”
  3. 突出显示“WEB-INF”目录
  4. 右键单击库容器(在右侧窗格中)
  5. 从上下文菜单中选择“放入/WEB-INF/lib”
  6. 输出布局中添加了 lib 文件夹

  7. 重建工件

  8. 重启网络服务器

Hope it helps.

希望能帮助到你。

screenshot

截屏

screenshot 2

截图 2

screenshot 4

截图 4

screenshot 3

截图 3