Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X
Dear Community,
inside OTK Java free I am registering another JLink application using BaseSession::StartJLinkApplication. This works fine. JLinkApplication::IsActive returns true and I can see the registered app in Creo (4.0). Furthermore I can register a task by using BaseSession::RegisterTask. But if I want to excecute the task (JLinkApplication::ExecuteTask) with the same TaskId that I used for registering the task I get a XToolkitNotFound exception. If I want to register another task with the same TaskId I get a XJLinkTaskExists exception.
I do not understand why! I also do not understand why I have to register a task on the BaseSession object but execute it on the JLinkApplication object.
Could anybody help?
Thank you and kind regards
Michael
Solved! Go to Solution.
It got it working now. As a matter of fact the registering of the task needs to happen inside the external application. That's where I got it wrong before. If you are interested see my example code.
The base application executing the task of the external application:
public class ExternalJLinkApplicationLauncher extends DefaultUICommandActionListener {
@Override
public void OnCommand() {
try {
JLinkApplication externalJLinkApp = pfcGlobal.GetProESession().StartJLinkApplication("externalJLinkApp",
"com.testing.ExternalJLinkApplication", "start", "stop", "C:\\path\\to\\classfiles", "C:\\path\\to\\textfolder", true);
String taskId = "externalJLinkApp001";
Argument dummyArgument = pfcArgument.Argument_Create("dummyArgument", pfcArgument.CreateASCIIStringArgValue("value"));
Arguments arguments = Arguments.create();
arguments.append(dummyArgument);
try {
externalJLinkApp.ExecuteTask(taskId, arguments);
} catch (XToolkitNotFound e) {
System.out.println("Task could not be found in target application.");
}
} catch (jxthrowable jxt) {
System.out.println(jxt.getMessage());
}
}
class ExternalJLinkAppListener extends DefaultJLinkTaskListener {
@Override
public Arguments OnExecute(Arguments arg0) throws jxthrowable {
System.out.println("externalJLinkApp started.");
return arg0;
}
}
}
The external application:
public class ExternalJLinkApplication {
private void registerTask() {
try {
String taskId = "externalJLinkApp001";
try {
pfcGlobal.GetProESession().RegisterTask(taskId, new ExternalJLinkAppListener());
} catch (XJLinkTaskExists e) {
System.out.println("Task " + e.GetTaskId() + " already exists.");
return;
}
} catch (jxthrowable jxt) {
System.out.println(jxt.getMessage());
}
}
public static void start() {
ExternalTestApp instance = new ExternalTestApp();
instance.registerTask();
}
public static void stop() {
}
class ExternalJLinkAppListener extends DefaultJLinkTaskListener {
@Override
public Arguments OnExecute(Arguments arg0) throws jxthrowable {
new JwPrintMessage().messageArea("TEST");
System.out.println("ExternalJLinkApplication started.");
return arg0;
}
}
}
Thank you all for your support and best regards!
I found only one article that is at least somehow related to your question: https://www.ptc.com/en/support/article/cs331890
Hi,
please ask PTC Support.
Difficult to understand what happened without a sources. Could you provide a sample of your code?
Thank you all for your replies! I will post the code as soon as I have some time, latest this weekend...
Kind regards
Michael
You're welcome.
It got it working now. As a matter of fact the registering of the task needs to happen inside the external application. That's where I got it wrong before. If you are interested see my example code.
The base application executing the task of the external application:
public class ExternalJLinkApplicationLauncher extends DefaultUICommandActionListener {
@Override
public void OnCommand() {
try {
JLinkApplication externalJLinkApp = pfcGlobal.GetProESession().StartJLinkApplication("externalJLinkApp",
"com.testing.ExternalJLinkApplication", "start", "stop", "C:\\path\\to\\classfiles", "C:\\path\\to\\textfolder", true);
String taskId = "externalJLinkApp001";
Argument dummyArgument = pfcArgument.Argument_Create("dummyArgument", pfcArgument.CreateASCIIStringArgValue("value"));
Arguments arguments = Arguments.create();
arguments.append(dummyArgument);
try {
externalJLinkApp.ExecuteTask(taskId, arguments);
} catch (XToolkitNotFound e) {
System.out.println("Task could not be found in target application.");
}
} catch (jxthrowable jxt) {
System.out.println(jxt.getMessage());
}
}
class ExternalJLinkAppListener extends DefaultJLinkTaskListener {
@Override
public Arguments OnExecute(Arguments arg0) throws jxthrowable {
System.out.println("externalJLinkApp started.");
return arg0;
}
}
}
The external application:
public class ExternalJLinkApplication {
private void registerTask() {
try {
String taskId = "externalJLinkApp001";
try {
pfcGlobal.GetProESession().RegisterTask(taskId, new ExternalJLinkAppListener());
} catch (XJLinkTaskExists e) {
System.out.println("Task " + e.GetTaskId() + " already exists.");
return;
}
} catch (jxthrowable jxt) {
System.out.println(jxt.getMessage());
}
}
public static void start() {
ExternalTestApp instance = new ExternalTestApp();
instance.registerTask();
}
public static void stop() {
}
class ExternalJLinkAppListener extends DefaultJLinkTaskListener {
@Override
public Arguments OnExecute(Arguments arg0) throws jxthrowable {
new JwPrintMessage().messageArea("TEST");
System.out.println("ExternalJLinkApplication started.");
return arg0;
}
}
}
Thank you all for your support and best regards!