UiPath Documentation
activities
latest
false

Actividades de desarrollador

Última actualización 21 de abr. de 2026

Ejecutar métodos estático y objeto

Para ejemplificar cómo utilizar este paquete de actividades, hemos creado un proceso de automatización que muestra sus capacidades de ejecución tanto de métodos estáticos como de objetos, dividido en dos partes:

  • For the first part, a Java library is initialized by using the Java Scope activity, then a .jar file containing the Java code is loaded by using Load Jar. A Static getArrayInt method is run by using the Invoke Java Method activity, returning an array of integers and storing it in a JavaObject custom data type. Then, by using the Convert Java Object activity, the JavaObject is converted to a .NET array of integers - an Int32[] variable. Each value it contains is then written in the Output panel via a For Each activity. This shows how easy it is to switch between specific Java and .NET data types and then manipulate their values any way you want.
  • En la segunda parte, dentro del mismo ámbito de Java mencionado anteriormente, se utiliza una actividad Crear objeto Java para crear otro JavaObject que contenga una clase Coordinate . Al utilizar otra actividad Invocar método Java , se ejecuta el método getCoordinateSum . Los métodos de objeto pueden llamarse de forma similar a los métodos estáticos pero, en lugar de utilizar TargetType, esta vez se utiliza la propiedad TargetObject , ya que ahora utilizamos una variable JavaObject en lugar de una matriz de enteros. El método devuelve sus valores en un tercero JavaObject y se convierte de nuevo en una variable .NET Double utilizando otra actividad Convertir objeto Java . El paso final es mostrar un Cuadro de mensaje que contiene el valor en la variable Double .

Así es como se puede crear la demostración:

El método estático

  1. Open Studio and start a new Process.
  2. Arrastra una actividad Ámbito de Java al Diseñador de flujo de trabajo. Como no se especifica ninguna ruta en la propiedad Ruta de la biblioteca de Java , el ámbito utiliza de forma predeterminada la variable de entorno PATH para inicializar la biblioteca de Java.
  3. Drag a Load Jar activity to the Designer panel.
  4. Assign the path to the Objects.jar file in the JarPath property field.
  5. Arrastra una actividad Invocar método Java después de Cargar jar.
  6. Input the method name in the MethodName property and then fill in the TargetType field with the Java package name and the class you want to use.
    Nota:

    The TargetType property must be specified in the form package.name.ClassName. For example, if we have a package called com.package.example which contains the class User.Profile and we want to use it, then the TargetType property should look like com.package.example.User.Profile.

  7. Create a JavaObject variable, called JavaObjectResultStaticMethod, to store the values returned by the Invoke Java Method activity and place it into the Result property field.
  8. Add a Convert Java Object variable to the workflow and place the JavaObjectResultStaticMethod variable into the JavaObject property field.
  9. In the TypeArgument property field, select the System.Int32[] variable type.
  10. Create a new Int32[] variable, called ResultStaticMethod, and add it in the Result property field.
  11. Next, drag a For Each activity to the Designer panel.
  12. Set the TypeArgument property to Int32, and assign the ResultStaticMethod variable to the Values property field. This enables you to go through each integer of your array.
  13. Drag a Write Line activity into the Body of the For Each activity and assign value.ToString into its Text property. This helps you write all the values in the ResultStaticMethod variable in the Output panel, at runtime.

El flujo de trabajo debería ser el siguiente:

Imagen de documentos

El método de objeto

  1. Add a Create Java Object activity to the workflow, under the Java Scope activity used in the previous example.
  2. Use the name of the Java package and the Coordinate class to fill in the TargetType property - uipath.java.test.Coordinate.
  3. Create a variable in the Result property field by using the Ctrl + K hotkey and name it JavaObject.
  4. Drag an Invoke Java Method activity to the Designer panel.
  5. To get the sum of the data returned by the Coordinate class, write the getCoordinateSum method into the MethodName property.
  6. Create a variable in the Result property field by using the Ctrl + K hotkey and name it JavaObjectResultObjectMethod.
  7. Add the JavaObject variable in the TargetObject field.
  8. Add a Convert Java Object activity to the workflow.
  9. Add the JavaObjectResultObjectMethod variable in the JavaObject field.
  10. In the TypeArgument property drop-down, select the System.Double datatype.
  11. Create a new Double variable, called ObjectMethodResultValue, and add it to the Result property field.
  12. Drag a Message Box to the Designer panel.
  13. Assign ObjectMethodResultValue.ToString to the Text property to display the values inside the Double variable. At runtime, the JavaObject is created, containing the Coordinate class, then the getCoordinateSum method is run and its results are returned in another JavaObject. The results are then converted to a .NET Double variable which is then displayed in a MessageBox.

El flujo de trabajo final debe parecerse a este:

Imagen de documentos

  • El método estático
  • El método de objeto

¿Te ha resultado útil esta página?

Conectar

¿Necesita ayuda? Soporte

¿Quiere aprender? UiPath Academy

¿Tiene alguna pregunta? Foro de UiPath

Manténgase actualizado