Questions tagged [jsr199]

JSR 199: Java Compiler API

Specification: JSR 199

9 questions
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
8
votes
3 answers

JavaCompiler from JDK 1.6: how to write class bytes directly to byte[] array?

So I recently learned of the new JavaCompiler API available in JDK 1.6. This makes it very simple to compile a String to a .class file directly from running code: String className = "Foo"; String sourceCode = "..."; JavaCompiler compiler =…
George Armhold
  • 30,824
  • 50
  • 153
  • 232
7
votes
1 answer

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.jar, I am not sure tools.jar associates with…
Brodie
  • 605
  • 1
  • 9
  • 17
4
votes
2 answers

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 diagnostics = new…
tzim
  • 1,715
  • 15
  • 37
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

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
1
vote
1 answer

how to use remote jars in classpath for javax.tools.JavaCompiler

I'm using JavaCompiler to compile .java code. It works for me while running the class compiled using URLClassLoader to load remote jars. But not work while compiling. Tried to use options like options.addAll(Arrays.asList("-classpath",…
Jiruffe
  • 47
  • 5
0
votes
2 answers

Malformed Java package class name while loading runtime-compile source

I have a Java runtime compiler as follows: public class Compiler { private final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); private final Map source = new HashMap(); private final…
John Ericksen
  • 10,995
  • 4
  • 45
  • 75
0
votes
2 answers

Dynamic Compiling Without Create Physical File

I follow the tutorial from Generating Java classes dynamically through Java compiler API, the code is work but what I see is the program will create a class file after compiling it. import java.io.IOException; import java.net.URI; import…
Crazenezz
  • 3,416
  • 6
  • 31
  • 59