InvocationTargetException using JCI
I try to run a simple main to compile(!) some java code. This is my pom:
And this is my main-class:
My output is:
(0:0) : Error while executing the compiler: java.lang.reflect.InvocationTargetException
What am I doing wrong?37 Replies
⌛
This post has been reserved for your question.
Hey @Peter Rader! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
Can you please show the full stack trace?
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
No stacktrace. Sorry.
Is the above the full error message?
Can you add a DiagnosticListener?
I dont know what a DiagnosticListener is. I could give you a github repo.
Yes
Oh I thought you were using the
JavaCompiler
API from https://docs.oracle.com/en/java/javase/21/docs/api/java.compiler/javax/tools/JavaCompiler.htmlJavaCompiler (Java SE 21 & JDK 21)
declaration: module: java.compiler, package: javax.tools, interface: JavaCompiler
Can you use
setCompilationProblemHandler()
and create a custom CompilationProblemHandler
?
to get more information about the errorSure I can. tbh, the JavaCompiler gives the same problem.
I set but the console does not print the dddd-line. I think the handler does not fire.
?
Did you try updating to version 1.1?
or even 2.0
What is printed with
System.out.println(result.getErrors()[0].getMessage());
?
or actually can you use a debugger and show the content of CompilationResult
?
or is that one returning null
?
Also it seems like that library is using Apache Commons Logging for quite some stuff - can you enable debug logging there?
Also are you getting any other result if you use a different compiler?
e.g. cf.createCompiler("eclipse")
Looking at the sources, the support for the Eclipse compiler is more complete in that libraryat least it isn't that: https://github.com/apache/commons-jci/blob/master/compilers/jsr199/src/main/java/org/apache/commons/jci2/compiler/jsr199/Jsr199CompilationProblem.java
GitHub
commons-jci/compilers/jsr199/src/main/java/org/apache/commons/jci2/...
Apache Commons JCI. Contribute to apache/commons-jci development by creating an account on GitHub.
(0:0) : Error while executing the compiler: java.lang.reflect.InvocationTargetException
Is that the message?
Yes
.
There is no version 1.1
There is no version 2
https://repo1.maven.org/maven2/org/apache/commons/commons-jci-core/
just not of
commons-jci-javac
Though I don't think JSR199 is supported
so jkust use the Eclipse compiler with 1.1I locked the transitive dependency 1.1 of -core using But the result remains the same.
As I said, don't use commons-cli-javac
Don't use javac there
that doesn't really seem supported any more
So they left a faulty
JavaCompiler API
in the jdk??
The one in the JDK is perfectly fine
No
but Apache Commons JCI doesn't have that any more
Same problem!
You haven't shown me the same thing with the JDK APIs
and unless you show me, it doesn't exist as far as I'm concerned
Yes, again! JavaCompiler API gives same problem.
you still haven't shown me
I will, give me a moment.
Note: I don't doubt that exception would be there but it probably has a reason and should give you more details if you properly ask for it
gives
(0:0) : Error while executing the compiler: java.lang.reflect.InvocationTargetException
.
I mean, it makes totaly sense! commons-jci-javac
is instrumenting javac!
commons-jci-core
is a wrapper that makes exactly this: com.sun.tools.javac.Main.compile(new String[] { ... });
src/main/java
?
Seriously?
That's com.sun.tools.javac
not javax.compiler
If it's in com.sun
, it's internal meaning you should probably not use itIt is a public-static-void-main(string[] args)
Its javac imo
Don't be so sure if you don't use it correctly
Until now, I haven't seen any correct use of https://docs.oracle.com/en/java/javase/21/docs/api/java.compiler/javax/tools/JavaCompiler.html from you
JavaCompiler (Java SE 21 & JDK 21)
declaration: module: java.compiler, package: javax.tools, interface: JavaCompiler
neither have I seen you using JCI version 1.1 with EJC
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.