Questions tagged [java-compiler-api]

A Java API for the Java compiler, available as javax.tools.JavaCompiler and related classes. (Use [javac] for questions about the command line compiler.)

181 questions
52
votes
23 answers

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 happen, I have backed to previous commit or different branch, which works find couple days ago, but has this error now. I have checked this question and there is not large image or…
Xianwei
  • 2,381
  • 2
  • 22
  • 26
46
votes
7 answers

Compile code fully in memory with javax.tools.JavaCompiler

I'm using the JavaCompiler from the javax.tools package (JDK 1.7) to compile some stuff on the fly, like this: compiler.run(null, null, "-cp", paths, "path/to/my/file.java"); It works but I would like to do it all in memory (e.g. pass a string with…
Sandman
  • 2,577
  • 2
  • 21
  • 32
44
votes
3 answers

How to set classpath when I use javax.tools.JavaCompiler compile the source?

I use the class javax.tools.JavaCompiler (jdk6) to compile a source file, but the source file depends on some jar file. How to set the classpath of the javax.tools.JavaCompiler?
Diablo.Wu
  • 1,151
  • 5
  • 15
  • 17
39
votes
1 answer

What is the difference between using javac and javax.tools.JavaCompiler?

Maven Compiler Plugin documentation states: The Compiler Plugin is used to compile the sources of your project. Since 3.0, the default compiler is javax.tools.JavaCompiler (if you are using java 1.6) and is used to compile Java sources. If you want…
Vic
  • 21,473
  • 11
  • 76
  • 97
33
votes
3 answers

Is it possible to programmatically compile java source code in memory only?

I have found many references explaining how to programmatically compile a Java class using the JavaCompiler class: JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); int result = compiler.run(null, null, null, "a_file_name"); However, I…
Sergio
  • 8,532
  • 11
  • 52
  • 94
18
votes
3 answers

Java annotation processing with source code manipulation

I have been looking for a solution for below requirement - Source files are written with Custom Annotation on a method Method body needs a little variation based on the annotation. Source file should not be changed, but input to compiler should be…
user1128134
  • 471
  • 6
  • 9
15
votes
5 answers

Why does Java not show an error for double semicolon at the end of a statement?

I accidentally wrote a java statement with two semicolons at the end. The java compiler does not show any error and it runs. Code: System.out.println("Length after delete the text is "+name.length());; For learning purposes I tried adding…
M.A.Murali
  • 9,988
  • 36
  • 105
  • 182
15
votes
3 answers

String too large to encode using UTF-8 written instead as 'STRING_TOO_LARGE'

Java compiler error: string too large to encode using UTF-8 written instead as 'STRING_TOO_LARGE'. I want to note, that there I have no long string and no one vector drawable that bigger than 32kb (biggest is 3.7kb). Gradle 3.2.0, build tool…
Tigran Babajanyan
  • 1,967
  • 1
  • 22
  • 41
14
votes
3 answers

Annotation Processor - How to get the Class it is processing

I am trying to write a custom Anntoation processor. The annotation processor will process each class file at compile time to check annotations, But how am i able to get the class that it is currently processing? I am only able to get the class name…
user1004413
  • 2,509
  • 6
  • 23
  • 33
11
votes
6 answers

Null Pointer Exception while using Java Compiler API

MyClass.java: package test; public class MyClass { public void myMethod(){ System.out.println("My Method Called"); } } Listing for SimpleCompileTest.java that compiles the MyClass.java file. SimpleCompileTest.java: package…
java_geek
  • 17,585
  • 30
  • 91
  • 113
11
votes
2 answers

JavaCompiler with custom ClassLoader and FileManager

I wish to compile source without having the dependencies present on the machine. Example: File A.java: import some.pkg.B; public class A extends B {...} I don't have B source present, I wish to hook either JavaFileManager or a custom ClassLoader…
Chen Harel
  • 9,684
  • 5
  • 44
  • 58
9
votes
2 answers

How to get a list of jar files and folders in classpath in Java 9?

I know you can't change the classpath in Java 9 because I read this: Add jar to classpath at runtime under java 9 I just want to list jar files and folders currently on the Classpath so that I can build a command line argument to the Java…
GlenPeterson
  • 4,866
  • 5
  • 41
  • 49
9
votes
1 answer

JavaCompiler API - slow compilation when running in tomcat

My application generates java code during runtime and compiles it using the JavaCompiler API. Some of the generated files can be rather large - up to a few hundred thousand lines. I find that when I run the javac command on the generated code in the…
Jewels
  • 966
  • 11
  • 28
9
votes
2 answers

Access constant field in annotation processor

Suppose a class defines a constant field: public class Foo { public static final int CONSTANT_FIELD = 3; } And suppose an annotation interface is declared like the following: public @interface Something { int value(); } Finally, suppose the…
Sam Harwell
  • 97,721
  • 20
  • 209
  • 280
8
votes
1 answer

Using JavaCompiler API in a Spring Boot app - unable to properly set the compilation classpath

We have an app that's been migrated from a traditional WAR Spring web application to what we had hoped would be a modern Spring Boot executable Jar. One of the app modules uses the JavaCompiler API to generate Java code and compile it in…
ronif
  • 695
  • 1
  • 6
  • 14
1
2 3
12 13