Java Idea 中的 Tomcat。战争爆发:服务器未连接。部署不可用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20163910/
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 Idea. war exploded: Server is not connected. Deploy is not available
提问by PaintedRed
I'm trying this tutoial. I created new project and ran it.
TomCat started, but then nothing happened. I can manually open in browser http://localhost:8080
and see the TomCat home page. It means server can be started. However I can't open index.jsp. Here is my screen after start:
screenshotAs you can see the project is running, but no info about passed environment variables.
No logs.
我正在尝试这个教程。我创建了新项目并运行它。TomCat 启动了,但随后什么也没发生。我可以在浏览器中手动打开http://localhost:8080
并查看 TomCat 主页。这意味着可以启动服务器。但是我无法打开 index.jsp。这是我启动后的屏幕:
screenshot正如你所看到的项目正在运行,但没有关于传递的环境变量的信息。没有日志。
I use TomCat 7.0.27
我使用 Tomcat 7.0.27
Idea 12.1.6
想法 12.1.6
on Opensuse 12.2
在 Opensuse 12.2 上
My tomcat HOME folder is /usr/share/tomcat
我的 tomcat HOME 文件夹是 /usr/share/tomcat
There was a problem:
Idea couldn't copy conf files from /usr/share/tomcat/conf to /home/loco/.IntelliJIdea12/system/tomcat//conf.
I executed chmod 777 *
in /usr/share/tomcat and the problem gone.
有一个问题:Idea 无法将 conf 文件从 /usr/share/tomcat/conf 复制到 /home/loco/.IntelliJIdea12/system/tomcat//conf。我chmod 777 *
在/usr/share/tomcat and the problem gone.
Also I changed the way how TomCat is started. It was default value
我还改变了 TomCat 的启动方式。这是默认值
/usr/share/tomcat/bin/catalina.sh run
I changed to
我改为
/usr/share/tomcat/bin/catalina.sh start
All other steps are done in accordance to tutorial.
所有其他步骤均按照教程完成。
采纳答案by codelark
The issue happens when a script in the tomcat startup set of scripts (most commonly setenv.sh
/ setenv.bat
) override the JAVA_OPTS
environment variable without including the original value. IDEA sets JAVA_OPTS
to tell tomcat to listen on 1099 for JMX requests for things like status and deployments.
当 tomcat 启动脚本集(最常见的setenv.sh
/ setenv.bat
)中的脚本覆盖JAVA_OPTS
环境变量而不包含原始值时,就会发生此问题。IDEA 设置JAVA_OPTS
告诉 tomcat 在 1099 上侦听 JMX 请求,例如状态和部署。
An example of a line from a setenv.sh
that will break:
来自 a 的setenv.sh
行将中断的示例:
export JAVA_OPTS="-XX:MaxPermSize=512m -Xmx1024m"
the corrected version:
更正后的版本:
export JAVA_OPTS="$JAVA_OPTS -XX:MaxPermSize=512m -Xmx1024m"
The same example lines from a windows setenv.bat
file:
来自 Windowssetenv.bat
文件的相同示例行:
set JAVA_OPTS=-XX:MaxPermSize=512m -Xmx1024m
and corrected:
并更正:
set JAVA_OPTS=%JAVA_OPTS% -XX:MaxPermSize=512m -Xmx1024m
If you only run tomcat from within IDEA, you can do as other have suggested and remove the line from your setenv
script and put the jvm options inside the IDEA run configuration.
如果您只在 IDEA 中运行 tomcat,您可以按照其他人的建议进行操作,并从setenv
脚本中删除该行并将 jvm 选项放入 IDEA 运行配置中。
回答by prule
I had this problem when I had set JAVA_OPTS in catalina.bat. Removing this meant that tomcat started and deployed as expected. The JAVA_OPTS values can be set in the Intellij Run config.
我在 catalina.bat 中设置 JAVA_OPTS 时遇到了这个问题。删除这意味着 tomcat 按预期启动和部署。JAVA_OPTS 值可以在 Intellij Run 配置中设置。
回答by Tim Cooper
I don't understand much about the theory of this, but I got the same error. After waiting a bit I got a message saying:
我不太了解这个理论,但我得到了同样的错误。等了一会儿,我收到一条消息:
Error during artifact deployment. See server log for details.
工件部署期间出错。有关详细信息,请参阅服务器日志。
I found the log file it presumably meant: "Tomcat localhost.log" and there was a stack trace there for a "NoClassDefFoundError" and "ClassNotFoundException". I did a refresh of Maven and a "Rebuild project" and that did the trick.
我发现日志文件可能意味着:“Tomcat localhost.log”,那里有一个“NoClassDefFoundError”和“ClassNotFoundException”的堆栈跟踪。我刷新了 Maven 和一个“重建项目”,就成功了。
回答by Christian Wilkie
I fixed this by removing my setenv.bat in $CATALINA_HOME/bin. Here were the settings inside:
我通过删除 $CATALINA_HOME/bin 中的 setenv.bat 解决了这个问题。这是里面的设置:
set JAVA_OPTS=-server -Xmx768m -XX:MaxPermSize=256M
I didn't need these options anymore, so I just removed the file. As prule's answer says, you can move these options to the Intellij Run config. After removing the file, deployment worked fine inside IntelliJ.
我不再需要这些选项,所以我只是删除了该文件。正如 prule 的回答所说,您可以将这些选项移动到 Intellij Run 配置。删除文件后,部署在 IntelliJ 中运行良好。
edit: For a better answer on why this works, check out codelark's answer below.Also, using his method you can keep your setenv.sh/setenv.bat files which is useful if you don't only run your Tomcat from inside IntelliJ IDEA.
编辑:为了更好地回答为什么会这样,请查看下面的 codelark 的答案。此外,使用他的方法,您可以保留 setenv.sh/setenv.bat 文件,如果您不仅从 IntelliJ IDEA 内部运行 Tomcat,这将非常有用。
回答by user2262727
Removing setenv.sh
from $CATALINA_HOME/bin
also worked for me.
I'm running tomcat7/Ubuntu/IntelliJ 12
删除setenv.sh
从$CATALINA_HOME/bin
也为我工作。我正在运行 tomcat7/Ubuntu/IntelliJ 12
With setenv.sh
in the bin folder, on startup inside IJ I see in the logs :
随着setenv.sh
在bin文件夹,里面IJ启动我看到在日志中:
/usr/local/tomcat/apache-tomcat-7.0.52/bin/catalina.sh run
[2014-07-28 02:41:39,274] Artifact TomcatDebug:war exploded: Server is not connected. Press 'Deploy' to start deployment.
Jul 28, 2014 2:41:40 PM org.apache.catalina.core.AprLifecycleListener init
odonovanj@ubuntuj:/usr/local/tomcat/apache-tomcat-7.0.52$ sudo netstat -tulpn|grep 2928
tcp6 0 0 :::8080 :::* LISTEN 2928/java
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 2928/java
tcp6 0 0 :::8009 :::* LISTEN 2928/java
After removing, in the logs I see : INFO: Server startup in 76 ms Connected to server [2014-07-28 02:44:35,847] Artifact TomcatDebug:war exploded: Artifact is being deployed, please wait... [2014-07-28 02:44:36,512] Artifact TomcatDebug:war exploded: Artifact is deployed successfully
删除后,在日志中我看到: INFO: Server startup in 76 ms Connected to server [2014-07-28 02:44:35,847] Artifact TomcatDebug:war purged: Artifact is being deploying, please wait... [2014- 07-28 02:44:36,512] Artifact TomcatDebug:war 爆炸:Artifact 部署成功
odonovanj@ubuntuj:/usr/local/tomcat/apache-tomcat-7.0.52$ sudo netstat -tulpn|grep 2346
tcp6 0 0 :::8080 :::* LISTEN 2346/java
tcp6 0 0 :::50044 :::* LISTEN 2346/java
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 2346/java
tcp6 0 0 :::8009 :::* LISTEN 2346/java
tcp6 0 0 :::1099 :::* LISTEN 2346/java
tcp6 0 0 :::52268 :::* LISTEN 2346/java
Seems like the setenv.sh
was overriding $JAVA_OPTS
, interfering with JNDI running on port 1099.
似乎setenv.sh
被覆盖$JAVA_OPTS
,干扰了在端口 1099 上运行的 JNDI。
回答by Макс Даниленко
(3.2) Set JRE_HOME or JAVA_HOME (required)
(3.2) 设置 JRE_HOME 或 JAVA_HOME (必填)
These variables are used to specify location of a Java Runtime Environment or of a Java Development Kit that is used to start Tomcat.
这些变量用于指定用于启动 Tomcat 的 Java 运行时环境或 Java 开发工具包的位置。
The JRE_HOME variable is used to specify location of a JRE. The JAVA_HOME variable is used to specify location of a JDK.
JRE_HOME 变量用于指定 JRE 的位置。JAVA_HOME 变量用于指定 JDK 的位置。
Using JAVA_HOME provides access to certain additional startup options that are not allowed when JRE_HOME is used.
使用 JAVA_HOME 可以访问使用 JRE_HOME 时不允许的某些附加启动选项。
If both JRE_HOME and JAVA_HOME are specified, JRE_HOME is used.
如果同时指定了 JRE_HOME 和 JAVA_HOME,则使用 JRE_HOME。
回答by Pleymor
I had this issue with Tomcat 7.0.27. I upgraded to Tomcat 8.0.21 and it fixed my problem :)
我在 Tomcat 7.0.27 上遇到了这个问题。我升级到 Tomcat 8.0.21,它解决了我的问题:)
回答by user5091911
file->project structure->Project SDK
then reconfigure the SDK.
然后重新配置SDK。
This really solved my problem.
这真的解决了我的问题。
回答by Hunger
I meet this problem when try to import a project from eclipse to IDEA.
尝试将项目从 eclipse 导入到 IDEA 时遇到此问题。
There is no setter.sh
in $CATALINA_HOME/bin
. The Project Structure
and Run Configuration
setting in IDEA looks OK, the whole project works normally in eclipse, but show this error in IDEA.
有没有setter.sh
在$CATALINA_HOME/bin
。IDEA中的Project Structure
andRun Configuration
设置看起来没问题,整个项目在eclipse中运行正常,但是在IDEA中显示这个错误。
My solution is, delete the .idea
folder, re-import the whole project. I don't know what's the accurate cause of this problem, but is works for me.
我的解决办法是,删除.idea
文件夹,重新导入整个项目。我不知道这个问题的确切原因是什么,但对我有用。
Now the log looks like that:
现在日志看起来像这样:
/Library/Tomcat/bin/catalina.sh run
[2015-09-22 12:40:57,906] Artifact bookstore:war exploded: Server is not connected. Deploy is not available.
XXXXXX
Connected to server
[2015-09-22 12:40:58,848] Artifact bookstore:war exploded: Artifact is being deployed, please wait...
XXXXXX
[2015-09-22 12:41:07,862] Artifact bookstore:war exploded: Artifact is deployed successfully
[2015-09-22 12:41:07,863] Artifact bookstore:war exploded: Deploy took 9,015 milliseconds
回答by gangdaner
A simple way is to change the port number in that file:
一种简单的方法是更改该文件中的端口号:
-Dcom.sun.management.jmxremote.port=1099
notice the port, default is 1099, but when use JMX, it may changed by you or someone, so, just simply change the port, that will be OK, no need to remove it from the tomcat bin folder.
注意端口,默认是1099,但是在使用JMX的时候,可能是你自己或者其他人修改的,所以,只要简单的修改一下端口就可以了,不需要从tomcat的bin文件夹中删除。