Book a Demo

Author Topic: Regarding connecting to the Java API and the use of java.library.path  (Read 3128 times)

Heidi V.

  • EA User
  • **
  • Posts: 23
  • Karma: +0/-0
    • View Profile
I spent some time on writing an application that connect to the Java API, so I thought I would document some of my findings in order to save others the time to find out the same things.

According to https://sparxsystems.com/enterprise_architect_user_guide/15.2/automation/automation_connect_setup.html, the first step is the following:

Quote
Copy the file:

      SSJavaCOM.dll

from the Java API subdirectory of your installed directory, usually:

      Program Files/Sparx Systems/EA

into any location within the Windows PATH

      windows\system32 directory.

Note:  Under 64-bit operating systems, the SSJavaCOM.dll file must be copied into C:\Windows\SysWOW64.

Under 64-bit versions of Windows, the 'System32' directory is for 64-bit applications, and 'SysWOW64' is for 32-bit applications.

A (cleaner?) way, that does not involve having to copy dll files – and that therefore does not require administrator rights on your machine, and that works also if you forget to copy these files when you update EA – is to call java with system property java.library.path. System property java.library.path is in the javadoc of the java.lang.System class defined as “List of paths to search when loading libraries” (that is, native libraries), see also https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/System.html, and loading libraries is done using method java.lang.System.loadLibrary(String).

So if "C:\Program Files (x86)\Sparx Systems\EA\Java API" is the folder that contains SSJavaCOM.dll and possibly also SSJavaCOM64.dll, then a Java application that connects to the EA interface can be called this way:

Code: [Select]
java -Djava.library.path="C:\Program Files (x86)\Sparx Systems\EA\Java API" -jar myapp.jar
Note: see also the static initializers in org.sparx.Services and org.sparx.Repository:

Code: [Select]
package org.sparx;

public class Services {
// ...

static {
if (System.getProperty("os.arch").equals("x86")) {
System.loadLibrary("SSJavaCOM");
} else {
System.loadLibrary("SSJavaCOM64");
}
}
}

Code: [Select]
package org.sparx;

import java.util.Date;

public class Repository {
// ...

static {
if (System.getProperty("os.arch").equals("x86")) {
System.loadLibrary("SSJavaCOM");
} else {
System.loadLibrary("SSJavaCOM64");
}

}
}