You want to use the command line to deploy a web application on WebLogic Server 7.0.
Use the Java-based weblogic.Deployer command-line utility, which is installed with WebLogic Server 7.0.
For developers or administrators who need to use the command line or shell scripts for deploying and redeploying web applications, WebLogic Server 7.0 provides the Java-based Deployer utility. This utility accomplishes the same tasks as using the graphical interface of the WebLogic Administration Console to deploy or redeploy a web application. First, this recipe describes how to deploy and redeploy a web application on the command line using the Deployer utility. Then the recipe provides an example of a Windows batch file that invokes the Deployer utility.
The Deployer utility is a Java-based program that requires the following JAR file on your classpath before the program can run: <BEA_HOME>\server\lib\weblogic.jar . "><BEA_HOME> represents the directory where WebLogic Server 7.0 was installed. The following command-line script on a Windows NT 4.0 machine redeploys the cookbook.war web application on a server named bwpserver :
java -cp k:\bea\weblogic700\server\lib\weblogic.jar; %CLASSPATH% weblogic.Deployer -adminurl http://localhost:7001 -user bwperry -name cookbook -source .\dist\cookbook.war -targets bwpserver -activate
This command-line invocation deploys the web application represented by the archive file cookbook.war , so the application is now available to receive requests with the context path /cookbook . When run on the command line, the program prompts the user for a password if you have not included it in the script with the -password option. The -source option specifies the location of the WAR file or web-application directory. The -targets option specifies one or more servers on which to deploy the web application. The final command for deploying the application is -activate .
This command-line invocation deactivates (makes unavailable) an existing web application on the server bwpserver . It prompts for the user password first, unless you add the -password option to the command line:
java -cp k:\bea\weblogic700\server\lib\weblogic.jar; %CLASSPATH% weblogic.Deployer -adminurl http://localhost:7001 -user bwperry -name cookbook -targets bwpserver -deactivate
The -cp option specifies the classpath to use for running the Deployer Java utility, and must include the weblogic.jar JAR file. The -adminurl switch specifies the administration server (the default value is http://localhost:7001 , so it does not have to be included here). The -name option specifies the name of the application to be deactivated, and the -targets option names the server where the application is running. The following command-line invocation redeploys the same "cookbook" application:
java -cp k:\bea\weblogic700\server\lib\weblogic.jar; %CLASSPATH% weblogic.Deployer -user bwperry -name cookbook -activate
This time, the -adminurl and -targets options were omitted. The default values for these switches are http://localhost:7001 and all current targets (if the developer is redeploying an existing application), respectively. If the application is being deployed for the first time, the default target for the -targets option is the administration server.
It is easier to run shell commands from a batch file, because there is less typing for complicated command-line programs and the shell scripts can be permanently saved. Example 2-7 is the first example rewritten as a batch file on Windows NT 4.0.
Example 2-7. Deploying an application
@echo off set WL_HOME=K:\bea\weblogic700 set BEA_CLASSPATH=%WL_HOME%\server\lib\weblogic.jar;%CLASSPATH% java -cp %BEA_CLASSPATH% weblogic.Deployer -adminurl http://localhost:7001 -user bwperry -name cookbook -source .\dist\cookbook.war -targets bwpserver -activate
This batch file sets two environment variables : WL_HOME and BEA_CLASSPATH . These are used to make sure that the classpath includes the weblogic.jar file, which contains the Deployer utility. If the script was saved as deploy.bat , this is how it would be run on the command line:
The resulting console output looks like this.
Enter a password for the user "bwperry":bwpserver_1968 Operation started, waiting for notifications... .... #TaskID Action Status Target Type Application Source 15 Activate Success bwpserver Server cookbook H:\book\ cookbook\.\dist\cook
Recipe 2.3 and Recipe 2.5; Recipe 2.7-Recipe 2.9; WebLogic's Server 7.0 programmer documentation: http://e-docs.bea.com/wls/docs70/programming.html.