209 questions
0
votes
1
answer
472
views
Cannot Export/Open Package from Module jdk.compiler to Run/Pass Tests in Maven
Settings
I'm using JDK 22:
openjdk version "22" 2024-03-19
OpenJDK Runtime Environment (build 22+36-2370)
OpenJDK 64-Bit Server VM (build 22+36-2370, mixed mode, sharing)
I'm also using ...
0
votes
0
answers
178
views
Use transitive maven dependency in an annotation processor inside the maven-compiler-plugin using the ServiceLoader
Top of the morning/noon/evening!
I have a multi project setup in which I use an annotation processor. This annotation processor is supposed to pickup Plugin instances (a custom interface) during the ...
0
votes
0
answers
99
views
How to modify java bytecode after compilation using compiler plugins?
I want to modify some java classes bytecode during/after compilation phase, but before packaging, in order to use custom invokedynamic bootstrap methods.
In order to do so, I have written a Java ...
0
votes
1
answer
25
views
Issues with jar exporter tool
I am attempting to write a Java project, which will compile any Java project and export a *.jar file. The program expects 3 runtime arguments, which I am specifying as:
C:\dev\Kronos\Kronos
vendor
src\...
0
votes
0
answers
647
views
Enable preview features for compiler plugin
I'm developing a compiler plugin for Javac. My codebase uses preview features, so I need to run using the flag --enable-preview. I can compile my code perfectly using maven, but when I try to do the ...
-1
votes
1
answer
139
views
Project packages cannot import Java compiler API: ClassNotFoundException / NoClassDefFoundError
I use Java compiler class inside my Spring Boot application as follows:
String classStr = "\n" +
"import java.util.List;\n" +
"import java.util.Map;\n" +
...
0
votes
2
answers
503
views
How to get parent tree object from JCTree in java?
How to get parent tree node from JCTree (com.sun.tools.javac.tree.JCTree) in Java?
For example:
public class MyTreeTranslator extends TreeTranslator {
@Override
public void visitMethodDef(...
0
votes
0
answers
216
views
JavaCompiler API in a Spring Boot app and get classpath
I'm using JavaCompiler API in Spring boot application. But currently I'm facing with an issue on getting spring boot runnable jar file classpath using System.getProperty("java.class.path") ...
1
vote
0
answers
117
views
How do you create a JavaCompiler instance for a JDK not on your path?
How do you create a JavaCompiler instance not on your system? More specifically, I would like to be able to create a JavaCompiler instance from a version number.
The only techniques I have seen for ...
3
votes
2
answers
1k
views
Cross Compilation in Java 13 and Java 8
I want to load a Java version specific JavaCompiler.
This is how I take compiler instance currently:
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
My aim is to compile a "user Java ...
2
votes
0
answers
321
views
Can ToolProvider.getSystemJavaCompiler() access runtime generated in memory source files when using JPMS modules?
I have developed an application that generates Java source at runtime from an external source. The generated source code implements an interface residing in say org.foo and also calls other classes ...
0
votes
1
answer
122
views
JavaCompiler API: access functions/variables outside the compiled program while it's running?
Adapting this the following code takes a class and function name, a string of Java code, compiles the code and runs the function.
public class Compile {
static void compileAndRun(final String ...
1
vote
1
answer
49
views
Non-essential imports compiled by javac
Just verified that javac compiles every reference or import that it sees, such as JavaDoc @link references.
Can this be turned off with an argument?
And/or, can a less eager compile be implemented ...
1
vote
0
answers
116
views
"Symbol not found" problem while trying to generat repositories at runtime
I'm trying to generate some repositories at runtime for spring data jpa with OpenHFT to reduce boilerplate code. The problem is, when running with IDEA it goes just fine, however if i run it in ...
-2
votes
1
answer
204
views
Interpreter and Compiler
Can any one help me in figuring out what compilers and interpreters are? And what their difference is ? Appreciate it if explained for Java beginner as I am one.
2
votes
1
answer
2k
views
Compile Java class in runtime with dependencies to nested jar
In a Spring Boot app I'm doing the following at runtime:
Generating a Java class
Compiling it
Accessing some static fields of the compiled class using reflection.
I've based my code on this post and ...
1
vote
0
answers
784
views
Is it possible to replace an implementation of a method of a dependency library in Java?
We have a situation where we are using some library and we would like to customize the logic of a tiny private method used in the library. Unfortunately, the library isn't well written to be extended.
...
0
votes
1
answer
159
views
Run JDT ASTVisitor on the output of Java Compiler
I am trying to write an extended Java Compiler that gives all the errors and warnings from javac plus some errors for custom unsupported java features.
Since this is going to run on a server, i would ...
0
votes
0
answers
1k
views
Annotation processor not working with Compiler API - Java
I have a task to compile java source file from source code. So I used JavaCompiler API. My java class annotated with Lombok annotation @Data. But when I compiled class exceptions are thrown.
Name....
62
votes
25
answers
109k
views
android studio with Java compiler error: string too large to encode using UTF-8 written instead as 'STRING_TOO_LARGE'
When I clean the android project in android studio, the error happens.
I have backed to previous commit or different branch, which worked fine couple days ago, but has this error now.
I have checked ...
0
votes
1
answer
464
views
How to compile and run scala code at runtime from a java program?
I already have a program that uses JavaCompiler api for compiling Java code at runtime. Can I use the same compiler for scala code? If not, what is the best way to compile scala code in a Java program?...
2
votes
2
answers
311
views
run() method of interface tool throws NullPointerException in JDK 9
//Following is Hello.java file.
public class Hello{
public static void main(String... s){
System.out.println("hello world");
}
}
I'm trying to compile the above class using Java ...
1
vote
2
answers
197
views
How do I check if the generated Java code adheres to the Java language specification?
I am working on a school project where I need to generate Java code that adheres to the Java Language Specs. So far I have been able to generate the Java code randomly which has valid syntax that ...
2
votes
0
answers
268
views
Can't use javax.tools.JavaCompiler when lombok is a dependency - getting NoClassDefFoundError [duplicate]
I'm trying to use JavaCompiler to compile a Java source at runtime:
$ cat src/main/java/App.java
import java.util.LinkedList;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
...
2
votes
1
answer
2k
views
How to use Java Compiler API to compile java files recursively?
I am learing Java Compiler API recently and I write some code that can compile one simple java source code file into a class file, but it can't compile a source code file which refer another class in ...