Skip to main content
17-Peridot
February 22, 2020
Solved

Add jars to a executable JAR file_OTK Java

  • February 22, 2020
  • 1 reply
  • 2137 views

Hello everyone!

Please tell me how to add dependencies (other jar files) to the project jar file.
For example, I want to use logging during development, but I can not start the application, since Creo throws an error that the class will not find.
I used the gradle build tool.

I pointed out the classpath in MANIFEST, added jar files inside my jar, but it still doesn't work.

My gradle code:

jar {
 //from {
 //	configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
 //}
 manifest {
 attributes(
 "Implementation-Title": "Jar Making Example",
 'Implementation-Version': "1.0",
 "Main-Class": "ru.Test",
 "Class-Path": configurations.runtimeClasspath.files.collect { it.getName() }.join(' ')
 )
 }
 destinationDirectory = file("build\\tmp\\jar")
 archivesBaseName = 'app'
 //C:\Program Files\PTC\Creo 5.0.2.0\Common Files\text\java\otk.jar
}

My jar:

VladiSlav_0-1582382860389.png

My MANIFEST:

VladiSlav_1-1582382905193.png

My code:

public class Test {
 
 private static final Logger log = LogManager.getLogger(Test.class);
 public static void start() throws jxthrowable {
 Session session = pfcSession.GetCurrentSessionWithCompatibility(CreoCompatibility.C4Compatible);
 session.UIShowMessageDialog("Hello", null);
 log.error("Hello!");
 }
 
 public static void stop() throws jxthrowable {
 
 }
}

This code works without the log4j2 classes in Creo.
Logging also works in the IDE if the start () method is started from the main () method.

 

Thanks in advance!
Best Regards!

Best answer by YaroslavSin

Hi,

you can add information about dependencies in the registry file called creotk.dat or protk.dat to field java_app_classpath.

 

For more info search CLASSPATH Variables and Registry File in documentation.

1 reply

17-Peridot
March 5, 2020

Hi,

you can add information about dependencies in the registry file called creotk.dat or protk.dat to field java_app_classpath.

 

For more info search CLASSPATH Variables and Registry File in documentation.

VladiSlav17-PeridotAuthor
17-Peridot
March 10, 2020

Thanks for the answer!