jsr199

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

此生再无相见时 提交于 2019-12-17 02:49:09
问题 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 ? 回答1: The javax.tools.JavaCompiler#getTask() method takes an options parameter that allows to set compiler options. The following message describes an easy way to set them in order to access the calling program's classpath: You need to configure the standard java file manager to know about the jar files(s) - you use

Does javax.tools depend on the JDK?

北慕城南 提交于 2019-11-30 15:23:30
问题 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 JRE. So, can I run the program in a JRE environment without JDK installed? Another question, what is the implementation detail of JavaCompiler , is it creating a new process to invoke the javac command? thanks 回答1: JRE's need to include the interfaces,

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

百般思念 提交于 2019-11-30 15:09:54
问题 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 = ToolProvider.getSystemJavaCompiler(); List<JavaSourceFromString> unitsToCompile = new ArrayList<JavaSourceFromString>() {{ add(new JavaSourceFromString(className, sourceCode)); }}; StandardJavaFileManager fileManager = compiler.getStandardFileManager(null,

Does javax.tools depend on the JDK?

早过忘川 提交于 2019-11-30 14:22:02
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 JRE. So, can I run the program in a JRE environment without JDK installed? Another question, what is the implementation detail of JavaCompiler , is it creating a new process to invoke the javac command? thanks Stephen Denne JRE's need to include the interfaces, and classes in that package, but do not need to provide implementations. Sun's JRE doesn't,

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

╄→гoц情女王★ 提交于 2019-11-30 13:42:39
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 = ToolProvider.getSystemJavaCompiler(); List<JavaSourceFromString> unitsToCompile = new ArrayList<JavaSourceFromString>() {{ add(new JavaSourceFromString(className, sourceCode)); }}; StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null); compiler.getTask(null, fileManager, null, null, null, unitsToCompile).call(); fileManager

Dynamic Compiling Without Create Physical File

感情迁移 提交于 2019-11-29 17:27:48
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 java.util.Arrays; import java.util.Locale; import java.util.logging.Level; import java.util.logging.Logger; import javax.tools.JavaCompiler.CompilationTask; import javax.tools.*; public class Compiler { static final Logger logger = Logger.getLogger(Compiler.class.getName()); static String sourceCode = "class HelloWorld{" + "public static void main (String

Dynamic Compiling Without Create Physical File

旧时模样 提交于 2019-11-28 12:34:55
问题 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 java.util.Arrays; import java.util.Locale; import java.util.logging.Level; import java.util.logging.Logger; import javax.tools.JavaCompiler.CompilationTask; import javax.tools.*; public class Compiler { static final Logger logger = Logger.getLogger(Compiler

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

假如想象 提交于 2019-11-26 14:38:50
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 ? The javax.tools.JavaCompiler#getTask() method takes an options parameter that allows to set compiler options. The following message describes an easy way to set them in order to access the calling program's classpath: You need to configure the standard java file manager to know about the jar files(s) - you use the compiler options argument to do that. By default the java compiler object only seems to know about the