FileDocCategorySizeDatePackage
WLRun.javaAPI DocApache Ant 1.7013611Wed Dec 13 06:16:24 GMT 2006org.apache.tools.ant.taskdefs.optional.ejb

WLRun

public class WLRun extends org.apache.tools.ant.Task
Starts a WebLogic server. A number of parameters are used to control the operation of the weblogic instance. Note that the task, and hence ant, will not complete until the weblogic instance is stopped.

Fields Summary
protected static final String
DEFAULT_WL51_POLICY_FILE
protected static final String
DEFAULT_WL60_POLICY_FILE
protected static final String
DEFAULT_PROPERTIES_FILE
private org.apache.tools.ant.types.Path
classpath
The classpath to be used when running the Java VM. It must contain the weblogic classes and the implementation classes of the home and remote interfaces.
private org.apache.tools.ant.types.Path
weblogicClasspath
The weblogic classpath to the be used when running weblogic.
private String
weblogicMainClass
private String
additionalArgs
Addional arguments to pass to the JVM used to run weblogic
private String
securityPolicy
The security policy to use when running the weblogic server
private File
weblogicSystemHome
The weblogic system home directory
private String
weblogicDomainName
The weblogic domain
private String
weblogicSystemName
The name of the weblogic server - used to select the server's directory in the weblogic home directory.
private String
weblogicPropertiesFile
The file containing the weblogic properties for this server.
private String
additionalJvmArgs
additional args to pass to the spawned jvm
private File
beaHome
The location of the BEA Home under which this server is run. WL6 only
private String
managementUsername
The management username
private String
managementPassword
The management password
private String
pkPassword
The provate key password - used for SSL
Constructors Summary
Methods Summary
public org.apache.tools.ant.types.PathcreateClasspath()
Add the classpath for the user classes

return
a path to be configured


                      
       
        if (classpath == null) {
            classpath = new Path(getProject());
        }
        return classpath.createPath();
    
public org.apache.tools.ant.types.PathcreateWLClasspath()
Get the classpath to the weblogic classpaths

return
a path to be configured

        if (weblogicClasspath == null) {
            weblogicClasspath = new Path(getProject());
        }
        return weblogicClasspath.createPath();
    
public voidexecute()
Do the work. The work is actually done by creating a separate JVM to run a helper task. This approach allows the classpath of the helper task to be set. Since the weblogic tools require the class files of the project's home and remote interfaces to be available in the classpath, this also avoids having to start ant with the class path of the project it is building.

exception
BuildException if someting goes wrong with the build

        if (weblogicSystemHome == null) {
            throw new BuildException("weblogic home must be set");
        }
        if (!weblogicSystemHome.isDirectory()) {
            throw new BuildException("weblogic home directory "
                + weblogicSystemHome.getPath() + " is not valid");
        }

        if (beaHome != null) {
            executeWLS6();
        } else {
            executeWLS();
        }
    
private voidexecuteWLS()

        File securityPolicyFile
            = findSecurityPolicyFile(DEFAULT_WL51_POLICY_FILE);
        File propertiesFile = null;


        if (weblogicPropertiesFile == null) {
            weblogicPropertiesFile = DEFAULT_PROPERTIES_FILE;
        }
        propertiesFile = new File(weblogicSystemHome, weblogicPropertiesFile);
        if (!propertiesFile.exists()) {
            // OK, properties file may be absolute
            propertiesFile = getProject().resolveFile(weblogicPropertiesFile);
            if (!propertiesFile.exists()) {
                throw new BuildException("Properties file "
                    + weblogicPropertiesFile
                    + " not found in weblogic home " + weblogicSystemHome
                    + " or as absolute file");
            }
        }

        Java weblogicServer = new Java(this);
        weblogicServer.setFork(true);
        weblogicServer.setClassname(weblogicMainClass);

        String jvmArgs = additionalJvmArgs;

        if (weblogicClasspath != null) {
            jvmArgs += " -Dweblogic.class.path=" + weblogicClasspath;
        }

        jvmArgs += " -Djava.security.manager -Djava.security.policy==" + securityPolicyFile;
        jvmArgs += " -Dweblogic.system.home=" + weblogicSystemHome;
        jvmArgs += " -Dweblogic.system.name=" + weblogicSystemName;
        jvmArgs += " -Dweblogic.system.propertiesFile=" + weblogicPropertiesFile;

        weblogicServer.createJvmarg().setLine(jvmArgs);
        weblogicServer.createArg().setLine(additionalArgs);

        if (classpath != null) {
            weblogicServer.setClasspath(classpath);
        }
        if (weblogicServer.executeJava() != 0) {
            throw new BuildException("Execution of weblogic server failed");
        }
    
private voidexecuteWLS6()

        File securityPolicyFile
            = findSecurityPolicyFile(DEFAULT_WL60_POLICY_FILE);
        if (!beaHome.isDirectory()) {
            throw new BuildException("BEA home " + beaHome.getPath()
                                     + " is not valid");
        }

        File configFile = new File(weblogicSystemHome, "config/"
            + weblogicDomainName + "/config.xml");
        if (!configFile.exists()) {
            throw new BuildException("Server config file " + configFile
                + " not found.");
        }

        if (managementPassword == null) {
            throw new BuildException("You must supply a management password "
                                    + "to start the server");
        }

        Java weblogicServer = new Java(this);
        weblogicServer.setTaskName(getTaskName());
        weblogicServer.setFork(true);
        weblogicServer.setDir(weblogicSystemHome);
        weblogicServer.setClassname(weblogicMainClass);

        String jvmArgs = additionalJvmArgs;

        jvmArgs += " -Dweblogic.Domain=" + weblogicDomainName;
        jvmArgs += " -Dweblogic.Name=" + weblogicSystemName;
        jvmArgs += " -Dweblogic.system.home=" + weblogicSystemHome;

        jvmArgs += " -Dbea.home=" + beaHome;
        jvmArgs += " -Djava.security.policy==" + securityPolicyFile;

        jvmArgs += " -Dweblogic.management.username=" + managementUsername;
        jvmArgs += " -Dweblogic.management.password=" + managementPassword;
        if (pkPassword != null) {
            jvmArgs += " -Dweblogic.pkpassword=" + pkPassword;
        }


        weblogicServer.createJvmarg().setLine(jvmArgs);
        weblogicServer.createArg().setLine(additionalArgs);

        if (classpath != null) {
            weblogicServer.setClasspath(classpath);
        }

        if (weblogicServer.executeJava() != 0) {
            throw new BuildException("Execution of weblogic server failed");
        }
     
private java.io.FilefindSecurityPolicyFile(java.lang.String defaultSecurityPolicy)

        String securityPolicy = this.securityPolicy;
        if (securityPolicy == null) {
            securityPolicy = defaultSecurityPolicy;
        }
        File securityPolicyFile = new File(weblogicSystemHome, securityPolicy);
        // If an explicit securityPolicy file was specified, it maybe an
        // absolute path.  Use the project to resolve it.
        if (this.securityPolicy != null && !securityPolicyFile.exists()) {
            securityPolicyFile = getProject().resolveFile(securityPolicy);
        }
        // If we still can't find it, complain
        if (!securityPolicyFile.exists()) {
            throw new BuildException("Security policy " + securityPolicy
                                    + " was not found.");
        }
        return securityPolicyFile;
    
public voidsetArgs(java.lang.String args)
Additional argument string passed to the Weblogic instance; optional.

param
args the argument string

        additionalArgs = args;
    
public voidsetBEAHome(java.io.File beaHome)
The location of the BEA Home; implicitly selects Weblogic 6.0; optional.

param
beaHome the BEA Home directory.

        this.beaHome = beaHome;
    
public voidsetClasspath(org.apache.tools.ant.types.Path classpath)
The classpath to be used with the Java Virtual Machine that runs the Weblogic Server; required. Prior to Weblogic 6.0, this is typically set to the Weblogic boot classpath. Under Weblogic 6.0 this should include all the weblogic jars

param
classpath the classpath to use when executing the weblogic server.

        this.classpath = classpath;
    
public voidsetDomain(java.lang.String domain)
Set the Domain to run in; required for WL6.0

param
domain the domain

        this.weblogicDomainName = domain;
    
public voidsetHome(java.io.File weblogicHome)
The location where weblogic lives. Required. This is the absolute location, not relative to BEA home.

param
weblogicHome the home directory of weblogic.

        weblogicSystemHome = weblogicHome;
    
public voidsetJvmargs(java.lang.String args)
Set the additional arguments to pass to the weblogic JVM

param
args the arguments to be passed to the JVM

        this.additionalJvmArgs = args;
    
public voidsetName(java.lang.String serverName)
The name of the weblogic server within the weblogic home which is to be run. Optiona, defaults to "myserver"

param
serverName the name of the server.

        this.weblogicSystemName = serverName;
    
public voidsetPKPassword(java.lang.String pkpassword)
Set the private key password so the server can decrypt the SSL private key file; optional and only applicable to WL6.0.

param
pkpassword the private key password,

        this.pkPassword = pkpassword;
    
public voidsetPassword(java.lang.String password)
Set the management password of the server; optional and only applicable to WL6.0.

param
password the management pasword of the server.

        this.managementPassword = password;
    
public voidsetPolicy(java.lang.String securityPolicy)
The name of the security policy file within the weblogic home directory that is to be used. If not specified, the default policy file weblogic.policy is used.

param
securityPolicy the security policy to use.

        this.securityPolicy = securityPolicy;
    
public voidsetProperties(java.lang.String propertiesFilename)
The name of the server's properties file within the weblogic home directory used to control the weblogic instance; required for WL4.5.1

param
propertiesFilename the properties file name

        this.weblogicPropertiesFile = propertiesFilename;
    
public voidsetUsername(java.lang.String username)
Set the management username to run the server; optional and only applicable to WL6.0.

param
username the management username of the server.

        this.managementUsername = username;
    
public voidsetWeblogicMainClass(java.lang.String c)
name of the main class for weblogic; optional.

param
c the name of the class

        weblogicMainClass = c;
    
public voidsetWlclasspath(org.apache.tools.ant.types.Path weblogicClasspath)
Set the weblogic classpath used by the Weblogic Server; optional, and only applicable to WL4.5.1 The weblogic classpath is used by weblogic to support dynamic class loading.

param
weblogicClasspath the weblogic classpath

        this.weblogicClasspath = weblogicClasspath;