jpmml / jpmml-transpiler

Java Transpiler (Translator + Compiler) API for PMML
GNU Affero General Public License v3.0
28 stars 2 forks source link

Show Java compiler errors (and warnings) to make the debugging of failed transpilations easier #19

Closed TPF2017 closed 2 years ago

TPF2017 commented 2 years ago

There is no error when I run directly, but IOException occurs when package to a jar file. My code id just like this `LoadingModelEvaluatorBuilder evaluatorBuilder = new LoadingModelEvaluatorBuilder().setVisitors(new DefaultModelEvaluatorBattery()).load(this.getClass().getResourceAsStream(pmmlFilePath));

Transpiler transpiler;

String filePath = "mymodel.pmml.jar";

String path = System.getProperty("user.dir");

filePath = path + File.separator + filePath;

transpiler = new FileTranspiler("com.mycompany.mymodel", new File(filePath));

evaluatorBuilder = evaluatorBuilder.transform(new TranspilerTransformer(transpiler));

Evaluator evaluator = evaluatorBuilder.build(); ` Error masage: java.io.IOException at org.jpmml.codemodel.CompilerUtil.compile(CompilerUtil.java:89) at org.jpmml.codemodel.CompilerUtil.compile(CompilerUtil.java:45) at org.jpmml.transpiler.TranspilerUtil.compile(TranspilerUtil.java:75) at org.jpmml.transpiler.Transpiler.compile(Transpiler.java:51) at org.jpmml.transpiler.FileTranspiler.transpile(FileTranspiler.java:46) at org.jpmml.transpiler.TranspilerTransformer.apply(TranspilerTransformer.java:40) at org.jpmml.evaluator.LoadingModelEvaluatorBuilder.transform(LoadingModelEvaluatorBuilder.java:142)

vruusmann commented 2 years ago

There is no error when I run directly, but IOException occurs when package to a jar file.

This is a Java compilation error (issued by javac.exe), so it should be happening always.

new LoadingModelEvaluatorBuilder().setVisitors(new DefaultModelEvaluatorBattery())

Don't use LoadingModelEvaluatorBuilder#setVisitors(VisitorBattery) in your general-purpose Java application good. You're likely to do more harm than good.

Will probably rename and/or hide this method in the JPMML-Evaluator 1.6.X development branch to stop its abuse.

TPF2017 commented 2 years ago

jpmml-debug.zip

This is a Java compilation error (issued by javac.exe), so it should be happening always.

I have wrote an example of my code, when I run: java -jar target/jpmml-debug-1.0-SNAPSHOT.jar I got an IOException, can you tell me how can I fix it?

vruusmann commented 2 years ago

Your sample PMML document (located in src/main/resources/data/) transpiles 100% successfully using JPMML-Transpiler version 1.1.16:

$ java -jar target/jpmml-transpiler-executable-1.1.16.jar --pmml-input src/main/resources/data/model.pmml --jar-output ./

I got an IOException, can you tell me how can I fix it?

Looks like your pom.xml combines JPMML-Evaluator and JPMML-Transpiler versions that ARE NOT API-WISE COMPATIBLE with each other.

The JPMML-Transpiler README states clearly that JPMML-Transpiler version 1.1.16 needs JPMML-Evaluator version 1.5.16 (or newer) to work. You're using 1.5.15 instead.

vruusmann commented 2 years ago

TLDR: The Java compiler is probably complaining about API mismatch here.

This is my hunch. Would be nice to see an actual Java compiler error message to be emitted to the console (or Java application logger) though.

TPF2017 commented 2 years ago

Looks like your pom.xml combines JPMML-Evaluator and JPMML-Transpiler versions that ARE NOT API-WISE COMPATIBLE with each other.

The JPMML-Transpiler README states clearly that JPMML-Transpiler version 1.1.16 needs JPMML-Evaluator version 1.5.16 (or newer) to work. You're using 1.5.15 instead.

I have changed JPMML-Evaluator version to 1.5.16 and the error still occurs. But if you just run MyApplication.java directly it will not report an error, what's the difference?

vruusmann commented 2 years ago

But if you just run MyApplication.java directly it will not report an error, what's the difference?

TLDR: My stuff works. Your stuff doesn't. You should debug your own stuff, not me.

Try compiling the translated com.company.model.Application Java source code file manually (on system console, using java.exe), and you shall see all compiler errors and warnings.