Questions tagged [javacompiler]

javax.tools.JavaCompiler is an interface used to invoke Java programming language compilers from programs. Not to be confused with Javac, which is the Java compiler included in the Java Development Kit (JDK).

Not to be confused with , the Java compiler included in the Java Development Kit (JDK) from Sun Microsystems.

javax.tools.JavaCompiler is an interface used to invoke programming language compilers from programs.

140 questions
1
vote
0 answers

javax.tools.JavaCompiler compile into byte[]

Is it possible for javax.tools.JavaCompiler to compile a file but return the bytecode into a byte[] and not actually creating a .class file?? My current code: DiagnosticCollector diagnostics = new DiagnosticCollector<>(); …
1
vote
1 answer

Facing NoClassDefFoundError despite jar being in classpath (dynamic compilation)

In a tomcat server, at run time, I am reading java class files and compiling them dynamically using the InMemoryJavaCompiler library which internally uses JavaCompiler . Code Sample - InMemoryJavaCompiler.newInstance() …
1
vote
3 answers

Getting java.lang.ClassNotFoundException when using package

I have a java file ComPac.java with the below code: package com; public class ComPac{ public static void main(String[] args) { System.out.println("Hello World"); } } The file is located at the path : /home/ec2-user/java_c To compile…
DockYard
  • 989
  • 2
  • 12
  • 29
1
vote
1 answer

I'm having trouble in running the code compiled using javax.tools.JavaCompiler

I am working on my first java project i.e., an TextEditor which can also compile and run files.The compiler (javax.tools.JavaCompiler) is working fine but when I try running ".class" file nothing shows up. I need help in that. Following is the code…
RC_602
  • 21
  • 3
1
vote
0 answers

JavaCompiler - Generated class not able to access generated enums

I am generating both the class and enums, and the generated code looks fine. The generated enums is in sub-package of the generated class. Generated class package - com.pkg1.pkg2 Generated enum package - com.pkg1.pkg2.enums I have a java test…
Aavik
  • 967
  • 19
  • 48
1
vote
1 answer

Gradle custom JavaCompile task for annotation processing

I am working on a gradle plugin that registers a JavaCompile task that should trigger an annotation processing process. Here is what I currently have private fun Project.runConfiguration(variants: DomainObjectSet) { …
AouledIssa
  • 2,528
  • 2
  • 22
  • 39
1
vote
0 answers

How java compiler handles duplicates variable names. What mechanism it uses?

Does it uses any data structure in which duplicates are not allowed. What exactly is the logic behind it.
1
vote
0 answers

Measure which Java code is taking long to compile

There is a large Java project that takes long to compile, both through Maven and through IntelliJ IDEA. I want to try to improve that, but you know what they say about optimization without measurement, so here we are. CPU use is at times 100% on all…
Mark
  • 18,730
  • 7
  • 107
  • 130
1
vote
0 answers

Android error Java compiler: uses or overrides a deprecated API

I have an error in Android when compiling, it tells me for a particular activity the following error: ..ruta\NameActivity.java: uses or overrides a deprecated API. Recompile with -Xlint:deprecation for details. Some input files use unchecked or…
1
vote
0 answers

"Symbol not found" problem while trying to generat repositories at runtime

I'm trying to generate some repositories at runtime for spring data jpa with OpenHFT to reduce boilerplate code. The problem is, when running with IDEA it goes just fine, however if i run it in external tomcat or simply in command line: "mvn…
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
1
vote
0 answers

Is it possible to replace an implementation of a method of a dependency library in Java?

We have a situation where we are using some library and we would like to customize the logic of a tiny private method used in the library. Unfortunately, the library isn't well written to be extended. So basically, imagine if we have a library with…
Oleksandr
  • 3,574
  • 8
  • 41
  • 78
1
vote
1 answer

How to use JavaCompiler from tools.jar without JDK

I am trying to create an application that can compile a provided .java file during runtime. I understand that there is a programmatical compiler available within the tools.jar of the JDK. However, I cannot guarantee that the user of the application…
rgoulazian
  • 13
  • 1
  • 2
1
vote
1 answer

java8 generic return type for varargs method broken?

I am facing a problem after I have switched from Java6 to Java8. Suddenly a java.lang.ClassCastException: java.base/java.lang.Integer cannot be cast to java.base/[Ljava.lang.Object; is thrown. It seems that the generic type cannot be matched to…
Matze
  • 93
  • 2
  • 10
1
vote
1 answer

Java JavaCompiler.run() compiling anonymous classes as well

I am trying to load in text files on the fly and compile them. File file = new File("Files/"+fileName+".java"); JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); compiler.run(null, null, errStream, file.getAbsolutePath()); I then will…
Todd Paul
  • 13
  • 2