209 questions
0
votes
2
answers
1k
views
JavaCompiler API force compile with errors?
I'm currently making a tool that will output Java class files for use based on user input. I have outputted a set of .java files, some of which reference classes and variables that don't exist in the ...
0
votes
3
answers
1k
views
JavaCompiler giving NullPointerException on "ToolProvider.getSystemJavaCompiler()". I'm pretty sure I have JDK set up right?
The section of code in question is:
String fileToCompile = "C:/Users/Jeff/Documents/Test/Compiler 6/examplejavafile.java";//Absolute path
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
...
1
vote
1
answer
509
views
using javax.tools.JavaCompiler etc
I am looking for working examples of Oracle's Java Compiler API usage. I want to build something close to javac to customize/extend errors logging capabilities.
-5
votes
3
answers
372
views
Unable to compile default package class referred in other classes using JavaCompiler [closed]
I have a situation where I need to compile classes dynamically.
Following is the structure in which my java classes have been organized.
// no package
public class A{
}
package test ;
public ...
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 ...
2
votes
0
answers
304
views
Compiler tree api: get fully qualified name
I am using Java Compiler Tree API for parsing java sources.
Currently i have run into the following issue. Consider I have a method which uses imported varible of type "Foo". The class Foo resembles ...
2
votes
1
answer
574
views
Java compiler tree api: NPE
I am trying to visit method body with another treepathscanner, but I dont know, which parameter to pass, because I allways get a NPE in TreePath constructor.
@Override
public Object visitMethod(...
0
votes
3
answers
396
views
Restricting Java Compiler API
I'm thinking of creating an in-game code IDE that uses a more restricted version of Java, for instance I do not want it to use the I/O stream APIs. Is this even possible?
Also, inb4 this. It still ...
5
votes
2
answers
324
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 ...
3
votes
2
answers
280
views
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 ...
0
votes
2
answers
3k
views
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....
1
vote
1
answer
1k
views
Compilation unit visitor - Java compiler tree api
I am using the compiler Tree api to parse my code into a AST, but the method visitCompilationUnit is never called, althrough the method visitClass is called, what am I doing wrong?
Second question: ...
0
votes
2
answers
451
views
Eclipse->New Android Projects always compile java 1.4
Everytime I add/create or copy a Project inside my Eclipse-Workspace it will be recognized as a Java 1.4 Project, which leads to a sum of errors. I have to fix this myself under properties->java-...
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 ...
-1
votes
3
answers
148
views
Get Classes from File
I have a sourcecode and in this source are two classes referenced.
Now I want to compile this code via JavaCompiler but therefore I have to first compile the two referenced classes.
Is there a ...
0
votes
2
answers
621
views
JavaCompiler not working in Jar
I got a java program which uses a JavaCompiler to generate new class files.
I use jdk 1.6 within eclipse and this works fine.
But when I export this as jar file and wan't to compile some .java ...
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 ...
2
votes
2
answers
1k
views
JavaCompiler, StandardJavaFileManager throws NPE
I want to compile a class from another class but every method I used throws a NullPointerException.
Here's the code:
File fRun = new File(fileToRun);
DiagnosticCollector<JavaFileObject> ...
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(...
0
votes
2
answers
2k
views
JavaCompiler returning null
I am creating a program along the lines of Codingbat.com.
During Runtime, it needs to compile code, and then execute it. This has all been handled.
Currently, I am forced to use the JavacTool, which ...
2
votes
3
answers
612
views
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 ...
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 ...
0
votes
3
answers
178
views
Compiling different scetions for different version - Java
Is there any way to compile BlackBerry Java code for different sections using eclipse ?
There is a class named LocationInfo available in BB version OS 6.0 onwards.
I get a compilation error if try ...
1
vote
1
answer
551
views
Is there a TreeVisitor for visiting expression trees in evaluation order?
Using the Java Compiler Tree API, one can traverse the leaf tree of a TreePath and its children using a TreeVisitor.
Is there a TreeVisitor implementation that visits all "nodes" in evaluation order? ...
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/...
1
vote
2
answers
398
views
Compiling within code, not getting behavior I'd like.
So I've got some code - I'd like to compile the string 'temp' then execute it, then change the string, recompile and execute. Problem is that currently it's just executing the first bit of code first....
-1
votes
3
answers
6k
views
How to compile .java file from within java program [duplicate]
Possible Duplicate:
Compiling external .java files from within Java
I have been using examples from all over the net but I keep getting NullPointerExceptions when invoking the run method in ...
1
vote
1
answer
172
views
JAXB compile error, unused parameters for afterUnmarshall
I'm using void afterUnmarshal(Unmarshaller unmarshaller, Object parent) in my beans and have got the complier set to fail if parameters are not used.
The compiler seems to be okay with unused ...
0
votes
1
answer
51
views
Java Character IO between java executions
Using javax.tools.JavaCompiler and javax.tools.ToolProvider, I'm wrapping a user-input string (which should be a method) with a predefined class all within a large string and executing it within my ...
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....
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[] ...
0
votes
1
answer
887
views
Java Compiler API NullPointerException
I am using this code to compile a Java file at runtime. First of all, here is my directory tree (in Eclipse).
+---- src
+----- package
+------ Compile.java
+
+
+---- temp
+----- anotherpackage
+------...
1
vote
1
answer
122
views
Java 5.0 Compiler API?
Is there a Java 5.0 equivalent to the Java 6.0 Compiler API? I'm trying to compile and jar some XmlBean schemas at runtime.
2
votes
3
answers
215
views
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. ...
1
vote
1
answer
243
views
Webstart and JavaCompiler API restrictions
I have an application that has only signed jars, all by the same certificate, mine. I wan't to run the application with Webstart. The application runs a compiler, and the compiled code runs LWJGL. ...
0
votes
2
answers
1k
views
The Java Compiler API does not work I keep getting unable to resolve class javax.tools.JavaCompilerTool and other similar ones
I have read that Java 6 has a compiler api which allows you to compile java files from other java code. However whenever I try to import any such class (eg javax.tools.JavaCompilerTool), I get a
...
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?!
1
vote
4
answers
3k
views
Modify byte code to make a method return true
I have class file has a method like this:
public boolean validate(String str) {}
There're lots of codes inside this validate method, but I only want to make it always return true or false. Can ...
1
vote
2
answers
2k
views
How to set the source for compilation by a CompilationTask
I do not know how to set the source file for a compilationTask.
I tried this:
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
List<String> optionList = new ArrayList<String&...
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 ...
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 ...
2
votes
2
answers
1k
views
How do I find the type declaration of an identifier using the Java Tree Compiler API?
I have the name of a variable/identifier, say, x, and the JCCompilationUnit and Scope. Is there a way to find the type of x?
1
vote
1
answer
363
views
Can I use JavaCompiler in Google app Engine?
Is there a way to invoke the Java source compiler via JavaCompiler in Google App Engine?
(I didn't see any classes in javax.tools on the white list, so I'm afraid the answer is no)
UPDATE
I'm ...
1
vote
1
answer
274
views
Running Java Code from Within Java [duplicate]
Possible Duplicates:
using eval in Java
Loading external source code and using them internally (by re-compiling or something)
I want to simulate an 'eval' in Java such that the function takes in ...
2
votes
4
answers
1k
views
Java Compiler API with classes that depend on each other
I'm using Java Compiler API to compile in-memory classes. That is, classes are compiled to bytecode (no .classes files stored in disk) and then loaded by reconstructing the bytecode.
Sometimes, I ...
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 ...
1
vote
1
answer
147
views
Java default compilation directory
I'm using the Java Compiler API to build a couple of classes at runtime. However, I'd like these classes to be compiled into the default compilation directory, to where other class files are generated....
2
votes
1
answer
844
views
Classpath of classes compiled with Javassist
As the title suggests, what is the classpath of classes compiled with Javassist?
My scenario is: Class A is compiled with Javassist. Class B is compiled with Java Compiler API and references Class A. ...
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 ...
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....