Entering content frame 'tab-interval:.25in'>

This graphic is explained in the accompanying text DeployExample.java Locate the document in its SAP Library structure

Purpose

This example deploys an application on a J2EE server.

Server Settings

The default settings are used for the server:

·        Host – localhost

·        Port – 3011

·        User – Administrator

·        Password – SAP

You can change these setting using the methods of the com.sap.engine.deploy.manager.LoginInfo interface.

Protocol Settings

The transport protocol is set to p4. It is the default transport protocol, you do not have to set it explicitly.

J2EE Application Settings

For the J2EE application:

·        You can overwrite the name of the application as provided in the XML file or preloaded with the setEar(java.lang.String earPath) method.

·        Set the name and path to the log file that will log information about the deploy process. It will be in the same directory as the class file and will be called DM_LOG.txt.

·        You should also set the system properties that are necessary so that the system can read the XML file of the EAR.

DeployExample.java

Package examples.deploy;

 

import com.sap.engine.deploy.manager.*;

import com.sap.engine.boot.SystemProperties;

 

/**

 * DeployExample.java

 *

 */

public class DeployExample extends Object {

 

  /**

   * This is the path to the EAR file, that is to be deployed.

   * The path can be either absolute or relative to the project

   * directory if it is set.

   */

  private String earFile = null;

 

  /**

   * Create a default login info host: [localhost], port [3011],

   * user [Administrator], psw []. To use another login, it is necessary

   * to set another host, port, user and password using

   * LoginInfo setMethods.

   */

  LoginInfo info = new LoginInfo();

 

  /**

   * Creates new DeployExapmle with path to the EAR file to be deployed.

   */

  public DeployExample(String ear) {

    earFile = ear;

  }

 

  public void startDeploy() {

    // Instantiates the deploy manager.

    DeployManager dm = new DeployManagerImpl();

    try {

      // Sets a path to the EAR file to be deployed.

      dm.setEar(earFile);

      // Changes the application name, if it is necessary.

      dm.setApplicationName("MyCalculator");

      // Sets a log file.

      dm.setLog(".\\DM_LOG.txt");

      //Sets login info to login to the SAP J2EE Engine.

      info.setUserPassword("sap");

      dm.setLoginInfo(info);

      //Sets a transport protocol. In this case it is "p4" only.

      dm.setSupport(new String[]{"p4"});

      //Deploy the application.

      dm.deploy();

    } catch (Exception e) {

      System.out.println("The Application MyCalculator cannot be deployed because:" + e.toString());

 

      return;

    }

    System.out.println("Application MyCalculator is deployed.");

    try {

      dm.startApplication("MyCalculator");

    } catch (Exception dme) {

      System.out.println("Application MyCalculator is deployed but cannot be started because:" + dme.toString());

      return;

    }

    System.out.println("Application MyCalculator is started.");

  }

 

  public static void main(String[] args) {

    // Sets the properties to make that the sap xml parser will be used.

    SystemProperties.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sap.engine.lib.jaxp.DocumentBuilderFactoryImpl");

    SystemProperties.setProperty("javax.xml.transform.TransformerFactory", "com.sap.engine.lib.jaxp.TransformerFactoryImpl");

    String earFile =  ".\\Calc.ear";

    DeployExample de = new DeployExample(earFile);

    de.startDeploy();

  }

}

 

 

 

Leaving content frame