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:
What am I doing wrong?
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>a</groupId>
<artifactId>a</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>22</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-jci-javac</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project><project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>a</groupId>
<artifactId>a</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>22</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-jci-javac</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>package a;
import java.nio.charset.StandardCharsets;
import org.apache.commons.jci.compilers.*;
import org.apache.commons.jci.readers.MemoryResourceReader;
import org.apache.commons.jci.stores.MemoryResourceStore;
public class Test {
public static void main(final String[] args) {
JavaCompilerFactory cf = new JavaCompilerFactory();
JavaCompiler compiler = cf.createCompiler("javac");
MemoryResourceReader pReader = new MemoryResourceReader();
int i = 0;
pReader.add("Test.java", "class Test{}".getBytes(StandardCharsets.UTF_8));
MemoryResourceStore pStore = new MemoryResourceStore();
CompilationResult result = compiler.compile(new String[] { pReader.list()[0] }, pReader, pStore,
Test.class.getClassLoader());
System.out.println(result.getErrors()[0]);
}
}package a;
import java.nio.charset.StandardCharsets;
import org.apache.commons.jci.compilers.*;
import org.apache.commons.jci.readers.MemoryResourceReader;
import org.apache.commons.jci.stores.MemoryResourceStore;
public class Test {
public static void main(final String[] args) {
JavaCompilerFactory cf = new JavaCompilerFactory();
JavaCompiler compiler = cf.createCompiler("javac");
MemoryResourceReader pReader = new MemoryResourceReader();
int i = 0;
pReader.add("Test.java", "class Test{}".getBytes(StandardCharsets.UTF_8));
MemoryResourceStore pStore = new MemoryResourceStore();
CompilationResult result = compiler.compile(new String[] { pReader.list()[0] }, pReader, pStore,
Test.class.getClassLoader());
System.out.println(result.getErrors()[0]);
}
}My output is:
(0:0) : Error while executing the compiler: java.lang.reflect.InvocationTargetException (0:0) : Error while executing the compiler: java.lang.reflect.InvocationTargetExceptionWhat am I doing wrong?