cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Using Apache POI with Java OTK for Creo

Rmorin
10-Marble

Using Apache POI with Java OTK for Creo

Hello,

I'm trying to use Apache POI to export some data to Excel in conjunction with an existing customization written with Java OTK. I'm using Eclipse on Windows. The project builds fine and loads in Creo, but it throws an exception when it gets to the first line of code that uses Apache POI. It says it's unable to find the class. Any thoughts would be greatly appreciated.

Thanks,

-Russ

ACCEPTED SOLUTION

Accepted Solutions
RandyJones
19-Tanzanite
(To:Rmorin)


@Rmorin wrote:

Thanks, Randy. I'm still not having any luck. I tried manually setting the CLASSPATH as you mention within the system window loaded from Creo.

Setting it in the system window, opened from Creo Parametric, will not affect Creo Parametric. You have to set it before starting Creo Parametric and then view the results of that in the Creo Parametric system window.

 

I echo it back and confirm that the correct JAR file is shown in addition to the otk.jar file, but it still can't find the class. Agreed that getting the CLASSPATH right can be a pain for Java in general, but this seems to be Creo specific. I sent a simplified version of my code off to PTC to see if they can figure it out.

Thanks,

-Russ


 

View solution in original post

12 REPLIES 12
RandyJones
19-Tanzanite
(To:Rmorin)

Could be several issues however most likely is incorrect CLASSPATH setting. Probably missing the apache poi jar in the Creo Parametric class path.

See https://www.ptc.com/en/support/article/CS000309245

Randy, what you're saying makes sense, but I'm still having trouble getting things to work. From your explanation, I now understand why my JAR builds correctly. because the Build Path is set properly in Eclipse. I just tried using config.pro add_java_class_path command, but I'm still not having any luck. Do you know if this can be set to a folder with a wildcard or if it must be set to a specific JAR? 

Thanks,

-Russ

Rmorin
10-Marble
(To:Rmorin)

Randy, I did try adding the external JARs to the classpath via all three methods described in that support article (https://www.ptc.com/en/support/article/CS000309245), but I'm still stuck with a class not found error. 

RandyJones
19-Tanzanite
(To:Rmorin)

I have never used the add_java_class_path or the java_app_classpath option to set the CLASSPATH. I always set it in a startup script for Creo Parametric or in a command prompt:

eg:

set CLASSPATH=%CLASSPATH%;%APPS_PREFIX%\java\class_files\ojdbc8.jar

Note the ';' separator between different members. The separator might be different for the add_java_class_path  config.pro option or the java_app_classpath  .dat option. PTC does not actually give an example in their article.

 

After that then fire up Creo Parametric > Open System Window

do an echo or set or something from the command prompt to see what the CLASSPATH is

eg

echo %CLASSPATH%

 

Than make sure that you can actually see the jar files listed as they are listed by doing something like a dir on the copied and pasted member(s) of the class path.

 

Getting the CLASSPATH set properly is actually more of a java question. There are bazillions of "How do I set my CLASSPATH?" questions and answers on google.

Thanks, Randy. I'm still not having any luck. I tried manually setting the CLASSPATH as you mention within the system window loaded from Creo. I echo it back and confirm that the correct JAR file is shown in addition to the otk.jar file, but it still can't find the class. Agreed that getting the CLASSPATH right can be a pain for Java in general, but this seems to be Creo specific. I sent a simplified version of my code off to PTC to see if they can figure it out.

Thanks,

-Russ

RandyJones
19-Tanzanite
(To:Rmorin)


@Rmorin wrote:

Thanks, Randy. I'm still not having any luck. I tried manually setting the CLASSPATH as you mention within the system window loaded from Creo.

Setting it in the system window, opened from Creo Parametric, will not affect Creo Parametric. You have to set it before starting Creo Parametric and then view the results of that in the Creo Parametric system window.

 

I echo it back and confirm that the correct JAR file is shown in addition to the otk.jar file, but it still can't find the class. Agreed that getting the CLASSPATH right can be a pain for Java in general, but this seems to be Creo specific. I sent a simplified version of my code off to PTC to see if they can figure it out.

Thanks,

-Russ


 

Thanks for the info, but there's still something wrong. I set the CLASSPATH outside of Creo before loading it and confirmed that the CLASSPATH shows as expected in the system window launched from within Creo. Even with that, I end up with the same error. There must be some subtle thing that isn't well documented that's causing this to fail, because I'm running "hello world" level code for this external library just to get something working.

 

Thanks,

-Russ

RandyJones
19-Tanzanite
(To:Rmorin)

Hopefully PTC will get back to you soon on the case you opened. Please let us know what the issue is. Maybe it will save me from future headaches...

Thanks, Randy. I think I finally solved it. You're help got me in the right direction, and the issue seemed to be an extra ";" at the end of my CLASSPATH that was throwing things off. I just marked your reply above as the solution. Thanks again!

RandyJones
19-Tanzanite
(To:Rmorin)

Glad you figured that out. That kind of an error will drive you nuts trying to figure it out.

I also confirmed that you can add an entire folder (not sure on sub-folders) with an asterisk at the end, and that it works when driven from the config.pro using the add_java_class_path command. Hope this helps someone else in my position in the future.

add_java_class_path C:\Users\Public\Downloads\jar_files\*

sjuraj
15-Moonstone
(To:Rmorin)

what build tool do you use ? .. how is your app deployed (as single or multiple jar files or not packed class files) ?

Announcements


Top Tags