我使用tomcat作为我的网络服务器。我有用户点击编辑按钮后需要重启tomcat服务器的应用程序。因为我已经在我的控制器上编写了如下代码:
if (updateResult ==1)
{
//String command = "/home/sunil_shiwankar/Tempo/apache-tomcat-6.0.32/startup.sh";//for linux use .sh
String command = this.getClass().getResource("/").getPath();
System.out.println("{{{{{{{{{{{{{{{{{{{{{{{{{{{"+ command);
command = command.replace(command.substring(command.lastIndexOf("webapps"), command.length()), "");
System.out.println("{{{{{{{{{{{{{{{{{{{{{{{{{{{ AFTER MODIFYING COMMAND IS "+ command);
try
{
String shutDownCommand = command+"bin/shutdown.sh";
Process child = Runtime.getRuntime().exec(shutDownCommand);
System.out.println("{{{{{{{{{{{{{{{{{{{{{{{{{{{ SHUTDOWN TOMCAT SUCCESSFULLY }}}}}}}}}}}}}}");
} catch (Exception e)
{
String inExceptionStartCommand = command+"bin/startup.sh";
Process child = Runtime.getRuntime().exec(inExceptionStartCommand);
System.out.println("{{{{{{{{{{{{{{{{{{{{{{{{{{{ TOMCAT STARTED WITH EXCEPTION SUCCESSFULLY }}}}}}}}}}}}}}");
e.printStackTrace();
}
String normalStartCommand = command+"bin/startup.sh";
Process child = Runtime.getRuntime().exec(normalStartCommand);
System.out.println("{{{{{{{{{{{{{{{{{{{{{{{{{{{ TOMCAT STARTED WITOUT EXCEPTION SUCCESSFULLY }}}}}}}}}}}}}}");
}
我的tomcat版本6.0.32,在运行我的应用程序时,它会异常关闭tomcat服务器并以异常启动
java.net.BindException: Address already in use <null>:8080
at org.apache.tomcat.util.net.JIoEndpoint.init(JIoEndpoint.java:549)
at org.apache.coyote.http11.Http11Protocol.init(Http11Protocol.java:176)
at org.apache.catalina.connector.Connector.initialize(Connector.java:1022)
at org.apache.catalina.core.StandardService.initialize(StandardService.java:703)
at org.apache.catalina.core.StandardServer.initialize(StandardServer.java:838)
at org.apache.catalina.startup.Catalina.load(Catalina.java:538)
at org.apache.catalina.startup.Catalina.load(Catalina.java:562)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:261)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.net.BindException: Address already in use
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:365)
at java.net.ServerSocket.bind(ServerSocket.java:319)
at java.net.ServerSocket.<init>(ServerSocket.java:185)
at java.net.ServerSocket.<init>(ServerSocket.java:141)
at org.apache.tomcat.util.net.DefaultServerSocketFactory.createSocket(DefaultServerSocketFactory.java:50)
at org.apache.tomcat.util.net.JIoEndpoint.init(JIoEndpoint.java:538)
... 12 more
16 Mar, 2011 10:17:43 AM org.apache.catalina.core.StandardService initialize
SEVERE: Failed to initialize connector [Connector[HTTP/1.1-8080]]
LifecycleException: Protocol handler initialization failed: java.net.BindException: Address already in use <null>:8080
at org.apache.catalina.connector.Connector.initialize(Connector.java:1024)
at org.apache.catalina.core.StandardService.initialize(StandardService.java:703)
at org.apache.catalina.core.StandardServer.initialize(StandardServer.java:838)
at org.apache.catalina.startup.Catalina.load(Catalina.java:538)
at org.apache.catalina.startup.Catalina.load(Catalina.java:562)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:261)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
请帮我解决
提前感谢
答案 0 :(得分:4)
该代码虽然难以阅读,但似乎并没有等待关机发生。我怀疑当你再次尝试启动它时它仍处于关闭状态。当然,异常表明它仍在运行,因为它的http端口仍在使用中。要暂时跟踪问题,请尝试在关机和启动之间进行一次休眠,看看是否能解决问题。
答案 1 :(得分:2)
其他一些应用程序已在侦听端口8080.终止该进程,然后运行您的服务器。一次只能有一个进程附加到进程。查找已绑定到该端口的进程是特定于操作系统的。
答案 2 :(得分:0)
我在端口8080遇到了同样的BindException问题。我按照以下步骤操作:
netstat -tulpn
它列出了所有进程ID和他们正在侦听的端口。然后我在列表中搜索端口8080然后查找其PID。 PID为1654.然后我使用以下命令终止了该过程:
kill -9 1654
然后我启动了tomcat服务器,它工作正常。希望能帮助到你! :)
答案 3 :(得分:0)
我也有这个问题,在我的情况下,在尝试配置Tomcat时,我创建了2个“引擎”。我在./conf/server.xml中有这样的一行:
<activity android:name=".CreateNewPost" android:parentActivityName=".MainActivity"></activity>
我更改了此设置以匹配早期server.xml中的设置:
<Engine name="Catalina" defaultHost="localhost">
我没有意识到这在./conf/Catalina/和./conf/Standalone/中创建了两个独立的配置。这两个冲突并给了我同样的错误。
我关闭了tomcat,删除了./conf/Catalina/和./conf/Standalone子目录,然后重新启动。 Tomcat创建了新的,没有更多的冲突!