209 questions
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 ...
48
votes
7
answers
44k
views
Compile code fully in memory with javax.tools.JavaCompiler [duplicate]
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 ...
45
votes
3
answers
22k
views
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?
39
votes
1
answer
7k
views
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)...
33
votes
3
answers
14k
views
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....
18
votes
3
answers
10k
views
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 ...
17
votes
3
answers
15k
views
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 ...
16
votes
3
answers
19k
views
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 (...
15
votes
5
answers
18k
views
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(...
11
votes
6
answers
15k
views
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....
11
votes
2
answers
8k
views
How to get a list of jar files and folders in classpath in Java 9? [duplicate]
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 ...
11
votes
2
answers
3k
views
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 ...
10
votes
4
answers
5k
views
Using Java Compiler API without requiring install of JDK
Hello All
I am writing some software that will allow users to create their own Java classes for a specific use in my software package. Obviously, my software will need to be able to invoke a Java ...
10
votes
2
answers
2k
views
Compile java files programmatically
I know this has been asked and answered a lot but I still don't have a good solution and I still don't understand some parts. So I have the requirement to compile *.java files programmatically.
...
9
votes
2
answers
1k
views
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 ...
9
votes
1
answer
434
views
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 ...
8
votes
1
answer
5k
views
Java compiler tree API - how do I set it up?
I wish to use the Java compiler tree in Eclipse. I have come across the API itself on the Oracle web site here, however I cannot find the JAR file for the library. Am I missing something?!
8
votes
1
answer
932
views
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 ...
7
votes
1
answer
13k
views
Can I add a method to a class from a compile time annotation?
If I create a custom annotation (example: @SaveFuncName("saveMe") will add a method called saveMe() with some code my processor generates), can the javac compiler use my annotation processor to add a ...
7
votes
1
answer
3k
views
Does javax.tools depend on the JDK?
I want to use JavaCompiler to dynamically create some classes.
I found the source code of the javax.tools package, but there is no implementation; some posts on the internet say it depends on tools....
7
votes
4
answers
3k
views
compiling and running user code with JavaCompiler and ClassLoader
I am writing web app for java learning. Using which users may compile their code on my serwer + run that code.
Compiling is easy with JavaCompiler:
JavaCompiler compiler = ToolProvider....
7
votes
1
answer
3k
views
How can I use JDT compiler programmatically?
I use JDT to compile my java classes. BatchCompiler returns a string but I need an array of problems/errors with their column and row information. compiler.compile(units); prints the error to its ...
6
votes
3
answers
7k
views
How do I use JDK6 ToolProvider and JavaCompiler with the context classloader?
My usage case is compiling generated source files from a java program using the ToolProvider and JavaCompiler classes provided in JDK 6. The source files contain references to classes in the context ...
6
votes
1
answer
5k
views
Using Java Compiler API to compile multiple java files
Hi I have requirement to create ,compile and load java classes run time. Using FTL i am creating java source files , and able to compile the source if there is no dynamic dependency.
To elaborate ...
6
votes
4
answers
3k
views
Java Dynamic Code Generation with support for generics
Is there any tool which provides Java dynamic code generation and that also supports generics?
Javassist for example, is the kind of tool that I need, but it does not support generics.
I wrote a ...
6
votes
4
answers
3k
views
Using javax.tools.ToolProvider from a custom classloader?
It seems to be impossible to use javax.tools.ToolProvider from a custom classloader as required by Ant or Webstart: https://bugs.java.com/bugdatabase/view_bug?bug_id=6548428
javax.tools.ToolProvider....
5
votes
1
answer
4k
views
JavaCompiler - set the compiled class output folder
I'm using Eclipse and therefore my class files are stored in "bin" in the project folder. How can I set the JavaCompiler to output compiled classes into this "bin" folder?
My code:
File fRun = new ...
5
votes
2
answers
325
views
Developing a java program to compile .java files
I am researching for a project that will involve my project to compile simple enough java files. From my research I have decided not to try and build my own compiler as this would just take too much ...
5
votes
2
answers
2k
views
Programmatically compile java with JavaCompiler?
I got this Java code from another Stack Overflow thread
import java.io.*;
import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
public class Main {
public static void main(String[] ...
5
votes
1
answer
1k
views
How to use the "classes" parameter of JavaCompiler.getTask()?
I'm trying to understand JavaCompiler.getTask(). I understand all the parameters except for the second to last one called classes. The Javadoc read:
class names (for annotation processing), null ...
4
votes
4
answers
11k
views
Java ClassLoader: load same class twice
I have a ClassLoader which loads a class compiled by JavaCompiler from a source file.
But when I change the source file, save it and recompile it, the ClassLoader still loads the first version of the ...
4
votes
1
answer
2k
views
Java Compilation task and classpath option not working
I was trying to create a class to compile some .java that I'll create at runtime, but I can't get this to work properly.
Here's my code
File bin = new File(args[args.length-1]);
System....
4
votes
1
answer
2k
views
Javassist Vs. Java Compiler API
In a project I'm currently working on, I need to generate Java classes at runtime.
I also need to avoid using reflection when using these classes later on.
I've been search for current solutions to ...
4
votes
2
answers
2k
views
how to run code compiled by JavaCompiler?
Is there any way to run program compiled by JavaCompiler? [javax.tools.JavaCompiler]
My code:
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
DiagnosticCollector<...
4
votes
1
answer
1k
views
How to dynamically compile Java classes in Google App Engine
In answers to this question, I learned that it is not possible to invoke the Java Compiler in javax.tools from a GAE app.
Does this limitation still apply?
If so, what are my options for compiling ...
4
votes
2
answers
2k
views
Compiling Java code from string results in ClassNotFoundException
I'm trying a code example that uses javax.tools to compile code that is in a string. The Class.forName results in a ClassNotFoundException. Does anybody know why? I'm using Java 7.
import ...
4
votes
1
answer
1k
views
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 ...
4
votes
3
answers
2k
views
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,...
4
votes
2
answers
328
views
How to pass -X options programmatically to the java compiler
JavaCompiler - How to pass -X options programmatically to the JavaCompiler class?
4
votes
1
answer
1k
views
Is there a way to generate a unique variable name in a given scope?
Given a Scope, is there a function that can generate a unique variable name such that a variable declaration for the unique name could be inserted in scope and the resulting source code/...
4
votes
2
answers
666
views
Compile Circular Dependency classes using javax.tools.JavaCompiler
I have been trying to compile some Java Classes in a String using java.
I have used javax.tools.JavaCompiler to compile the Classes in the Strings.
I have made instances of SimpleJavaFileObject by a ...
3
votes
1
answer
6k
views
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 ...
3
votes
2
answers
3k
views
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 ...
3
votes
2
answers
2k
views
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 ...
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 ...
3
votes
1
answer
653
views
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 ...
3
votes
1
answer
928
views
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 ...
3
votes
1
answer
1k
views
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 ...
3
votes
1
answer
818
views
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 ...
3
votes
2
answers
206
views
Compiling java Code Available In A String within another java code [duplicate]
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 ...