Setting Environment Variables with the Launch Application Robot
This topic provides a sample of using an expression in a Launch Application robot node to launch executables and pass in parameters to the launched application.
Referenced Workflow
ApplicationLaunchExample.xml
Description
The Launch Application robot node can be used to launch executables and pass in parameters to the launched application. The command line below runs a Java class and passes it to three string arguments. For this sample, define the Launch Application robot node that contains this command line as asynchronous.
Instructions
1. Create three string variables in the template: name, date, and message. Give them initial values. Note that in order to assign more than one word to a variable, you must enclose it in quotation marks ("). For example, to assign Hello how are you to the variable message, you would specify the value as "Hello how are you".
2. Create an environment variable called classpath in the Application robot, and set its value to the jdk folder on your machine and the folder where the Java class resides.
3. Create a Java file with this code ("Code for Java file") and compile it. Make sure its path is in the classpath variable above.
4. Copy the following code:
java MessageDisplay {name} {date} {message}
Code for Java File
import java.awt.*;

import java.awt.event.*

public class MessageDisplay extends Frame{

public MessageDisplay( ) {

//{{ INIT_CONTROLS

setLayout(null );

setSize(628,389);

label1 = new java.awt.Label( "Hello", Label.RIGHT );

label1.setBounds(108,36,103,22);

label1.setFont(new Font( "Dialog", Font.BOLD , 16));

add(label1);

label2 = new java.awt.Label( "Date", Label.RIGHT );

label2.setBounds(103,72,103,24);

label2.setFont(new Font( "Dialog", Font.BOLD , 16));

add(label2);

label3 = new java.awt.Label( "Message", Label.RIGHT );

label3.setBounds(103,108,103,27);

label3.setFont(new Font( "Dialog", Font.BOLD , 16));

add(label3);

TFName = new java.awt.TextField( );

TFName.setBounds(228,24,280,28);

add(TFName );

TFDate = new java.awt.TextField( );

TFDate.setBounds(228,60,276,26);

add(TFDate );

TAMessage = new java.awt.TextArea( );

TAMessage.setBounds(228,96,285,164);

add(TAMessage );

OK = new java.awt.Button( );

OK.setLabel( "OK");

OK.setBounds(312,276,70,25);

OK.setBackground(new Color(12632256));

add(OK );

LError = new java.awt.Label( "Wrong number of arguments. Please rerun with 3 arguments ");

LError.setVisible(false );

LError.setBounds(12,324,601,29);

LError.setFont(new Font( "Dialog", Font.BOLD , 16));

add(LError );

setTitle( "Untitled");

//}}

//{{ REGISTER_LISTENERS

SymWindow aSymWindow = new SymWindow( );

this.addWindowListener(aSymWindow );

SymAction lSymAction = new SymAction( );

OK.addActionListener(lSymAction );

//}}

}

public MessageDisplay(String title)

{

this( );

setTitle(title );

}

public void setVisible(boolean b)

{

if(b )

{

setLocation(50, 50);

}

super.setVisible(b );

}

static public void main(String args[ ])

{

MessageDisplay myFrame = new MessageDisplay( );

myFrame.setVisible(true );

myFrame.displayMessage(args );

}

public void addNotify( )

{

// Record the size of the window prior to calling parents addNotify .

Dimension d = getSize( );

super.addNotify( );

if ( fComponentsAdjusted )

return;

// Adjust components according to the insets

setSize(insets( ).left + insets( ).right + d.width , insets( ).top + insets( ).bottom + d.height );

Component components[ ] = getComponents( );

for (int i = 0; i < components.length i++ )

{

Point p = components[i ]. getLocation( );

p.translate(insets( ).left, insets( ).top);

components[i ]. setLocation(p );

}

fComponentsAdjusted = true;

}

// Used for addNotify check.

boolean fComponentsAdjusted = false;

//{{ DECLARE_CONTROLS

java.awt.Label label1;

java.awt.Label label2;

java.awt.Label label3;

java.awt.TextField TFName

java.awt.TextField TFDate

java.awt.TextArea TAMessage

java.awt.Button OK;

java.awt.Label LError

//}}

class SymWindow extends java.awt.event.WindowAdapter

{

public void windowClosing(java.awt.event.WindowEvent event)

{

Object object = event.getSource( );

if (object == MessageDisplay.this )

MessageDisplay_WindowClosing(event );

}

}

void MessageDisplay_WindowClosing(java.awt.event.WindowEvent event)

{

setVisible(false ); // hide the Frame

}

public void displayMessage(String args[ ]){

if ( args.length < 2){

LError.setVisible(true );

LError.setText( "Wrong number of arguments. Please rerun with 2 arguments");

}

else {

LError.setVisible(false );

TFName.setText(args[0]);

TFDate.setText(args[1]);

TAMessage.setText(args[2]);

}

}

class SymAction implements java.awt.event.ActionListener

{

public void actionPerformed(java.awt.event.ActionEvent event)

{

Object object = event.getSource( );

if (object == OK)

OK_ActionPerformed(event );

}

}

void OK_ActionPerformed(java.awt.event.ActionEvent event)

{

setVisible(false );

system.exit(0)

}

}
Isto foi útil?