Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to load pre-transpiled PMML service provider JAR files? #257

Closed
OOYXLOO opened this issue Jan 6, 2023 · 2 comments
Closed

How to load pre-transpiled PMML service provider JAR files? #257

OOYXLOO opened this issue Jan 6, 2023 · 2 comments

Comments

@OOYXLOO
Copy link

OOYXLOO commented Jan 6, 2023

How can I get an Evaluator from xxx.pmml.jar through the ServiceLoadingModelEvaluatorBuilder in a packaged jar?

I can't use this.getClass().getClassLoader().getResource("xxx.pmml.jar") to get the URL which is needed in SerciceLoadingModelEvaluatorBuilder.loadService to get an Evaluator because in a packaged jar I can't get the path.

I know that I can use LoadingModelEvaluatorBuilder to get an Evaluator from a xxx.pmml, but the unmarshal step will cost much time when I need to load abundant models.

I hope that someone can help me to solve this problem

@vruusmann
Copy link
Member

How can I get an Evaluator from xxx.pmml.jar through the ServiceLoadingModelEvaluatorBuilder in a packaged jar?

The Java API can be derived from the class name: "serviceLoading" + "builder":

URL serviceJarURL = ...;

// First do "loadService", then do "build"
Evaluator evaluator = new ServiceLoadingModelEvaluatorBuilder()
	.loadService(serviceJarURL)
	.build();

I can't use this.getClass().getClassLoader().getResource("xxx.pmml.jar")

The ClassLoader#getResource(String) method is looking for a resource inside classpath JAR files.

Your xxx.pmml.jar service JAR file is not located inside any other JAR files, it is a standalone top-level JAR file all by itself (that's how it's supposed to work, if you have generated a "wrapped JAR file" already, then please unwrap it).

More importantly, the xxx.pmml.jar service JAR file does not need to be on your Java application's classpath. The Java classloader only knows about classpath contents so, by design, this xxx.pmml.jar service JAR file can/should be unknown to Java classloader initially.

I know that I can use LoadingModelEvaluatorBuilder to get an Evaluator from a xxx.pmm

The right question to ask is "how can I obtain a java.net.URL object pointing to my xxx.pmml.jar?"

Assuming a file in local filesystem:

File serviceJarFile = new File("/path/to/xxx.pmml.jar");

URL serviceJarURL = (serviceJarFile.toURI()).toURL();

Assuming a resource on some publicly accessible web seriver:

URL serviceJarURL = new URL("https://myserver.com/mydir/xxx.pmml.jar");

.. but the unmarshal step will cost much time when I need to load abundant models.

Yep, that's one valid reason for choosing JPMML-Transpiler over the standard JPMML-Evaluator - transpiled models do not have any Ja(va|karta) XML Binding dependencies, and they load blazing fast.

@vruusmann vruusmann changed the title ServiceLoadingModelEvaluatorBuilder.loadService How to load pre-transpiled PMML service provider JAR files? Jan 6, 2023
@OOYXLOO
Copy link
Author

OOYXLOO commented Jan 7, 2023

Thank you very much, I will solve the problem according to your suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants