开发者

How to stop an Apache 2 HTTP server from a Java program?

I start an Apache HTTP server within my Java program. Unfortunately, I cannot stop the server from the program through the "httpd.exe -k stop" command. The error message is "(OS 5)Access is denied. : Failed to open the Apache2.2 Ser开发者_如何学Govice". My OS is Windows 7. How can I stop the server from my Java program? (Stopping manually the server is not an option.)

UPDATE: I cannot change the Windows permissions.


A dirty--but plain java--solution is to call:

Runtime.getRuntime().exec("taskkill /F /IM httpd.exe");


It might be possible to write a CGI script, deploy it into Apache and call that from Java.

In theory the script would run with the same privileges as Apache itself and could contain the code necessary to stop the server ( apachectl -k stop ).

For security , the CGI script would only accept localhost connections and would require a password. If all requirements are met, it would issue the call above.


Looks like you need to run your program as an administrator. Take a look at this question: Java: run as administrator


1). Goto Start 2). In the search box type "services" 3). Click on "services" and you will find your apache installed from the list. 4). select apache and you will find the options of start/restart/stop on the left of your screen or you will find the options of start/restart/stop by right clicking on the apache. 5). After this it is self explanatory. Note 1:- In case changes such as start/restart/stop are not taken up immediately , you may have to restart windows. Note 2:- This is an alternate solution to your problem . It is a best practice to restart via Apache application itself. Nevertheless, the above mentioned method mostly works at least as of now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜