A Java API for the Java compiler, available as javax.tools.JavaCompiler and related classes. (Use [javac] for questions about the command line compiler.)
Questions tagged [java-compiler-api]
181 questions
4
votes
3 answers
Use webapp classpath using JavaCompiler in Tomcat within Eclipse with Maven
I have an existing "Example Webapp" that references "Example Library" using Maven. I'm running Tomcat 7 inside Eclipse 4.3RC3 with the m2e plugin. When I launch Example Webapp on Tomcat inside Eclipse, I have verified that the example-library.jar is…

Garret Wilson
- 18,219
- 30
- 144
- 272
4
votes
1 answer
How to compile multiple Java classes in one go using the JavaCompiler API
I am new to java and I am following this tutorial as it is very informative and explains everything in great detail. At the bottom of the tutorial it explains how a JavaFileManager can be used to compile multiple java files and gives a few examples…

flexinIT
- 431
- 2
- 10
- 28
3
votes
1 answer
How to validate Java code programatically?
Given the source code and the Java version, I need to be able to validate whether or not the code will compile. If the code does not compile, I need to be able to return the errors within the source code.
The following solution works, but only for…

Lindstorm
- 890
- 2
- 7
- 22
3
votes
2 answers
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 code" according to the Java version (Java 8 or Java…

niranjan_harpale
- 2,048
- 1
- 17
- 21
3
votes
1 answer
Memory leak in program using compiler API
I have detected a severe memory leak in a piece of code that is used for compiling and running Java code in run time. I have created heap dumps and it seems com.sun.tools.javac.util.SharedNameTable$NameImpL is the culprit.
What I'd like to know is…

Hartger
- 329
- 1
- 14
3
votes
1 answer
How to compile protocol buffers schema at runtime?
I can create the schema (Descriptors.Descriptor) at runtime dynamically using FileDescriptorProto, also I'm able to serialize and deserialize messages using DynamicMessage.
However performance of DynamicMessage is not good enough because of the way…

Boyolame
- 329
- 2
- 13
3
votes
1 answer
java runtime class generation frameworks
I want to have one feature of Java 8 for Java 7: automatic interface implementation generation for method (to avoid performace deficiency due to reflection calls). I know that Java 8 provide the generation at compile time but I think it's not…

Sergiy Medvynskyy
- 11,160
- 1
- 32
- 48
3
votes
2 answers
How to set up classpath of JavaCompiler to multiple .jar files using wildcard
I am using JavaCompiler of javax.tools to compile some java code and I am trying to use wildcard in my classpath in order to include all the .jar files but I fail.
Here is my code:
String classpath =…

NikosDim
- 1,398
- 2
- 21
- 40
3
votes
1 answer
Compiling a set of Java files inside a directory tree with the JSR 199 Compiler API
I'm trying to compile many files using the Compiler API.
Say I have a directory structure
.../program
+/org
+/foo
|+ Main.java
+/bar
+ Tools.java
Is there any way to discover all the Java files and make it compiler everything…

Flame
- 2,166
- 2
- 20
- 40
3
votes
2 answers
Why is Grails using an old JVM compiler on Mac OS x 7?
Mac OS x 10.7
grails> !java -version
java version "1.7.0_13"
Java(TM) SE Runtime Environment (build 1.7.0_13-b20)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)
grails> !which…

Alexander Paul Wansiedler
- 484
- 7
- 17
3
votes
1 answer
clear the class loaded through class.forName in java
I have created program which loads a java(JPanel) file which user chooses.User basically chooses a Java file which gets compiled by JavaCompiler and next generated class file is loaded.
But problem is coming when any changes are done in the java…

WitVault
- 23,445
- 19
- 103
- 133
3
votes
2 answers
Compiling java Code Available In A String within another java code
Possible Duplicate:
On-the-fly, in-memory java code compilation for Java 5 and Java 6
Compiling Java file with code from within a Java file
i have a hello world class available in the string of a program as given in the example below,
public…

adeel iqbal
- 494
- 5
- 23
3
votes
2 answers
NoSuchMetodError Exception when Access Custom Library
I have a problem regarding java.lang.NoSuchMethodError. This program is about Compiler API (JSR 199). When I create a prototype for this it run work, but when I try to make it to become library it throw NoSuchMethodError Exception.
Here is the First…

Crazenezz
- 3,416
- 6
- 31
- 59
2
votes
3 answers
Best choice? Edit bytecode (asm) or edit java file before compiling
Goal
Detecting where comparisons between and copies of variables are made
Inject code near the line where the operation has happened
The purpose of the code: everytime the class is ran make a counter increase
General purpose: count the amount of…

tgoossens
- 9,676
- 2
- 18
- 23
2
votes
3 answers
How can I load a class which is not in the same jar archive as the current class?
Situation:
I'm making a simulator for plotting the time complexity of algorithms. The students can add load their own .java file to run it.
My program compiles (with 'JavaCompiler') the .java file. Then it tries to load the .class file:
loadedClass…

tgoossens
- 9,676
- 2
- 18
- 23