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
2
votes
1 answer

Risks for locks in try-with-resources blocks in Java 8

If I do try(Lock lock = lockProvider.lock()) { // some code that doesn't use variable lock } Is there a risk that the compiler or the JITer to remove the lock creation because it sees it as unused inside the block? Later Edit: A bit of…
Andrei Rînea
  • 20,288
  • 17
  • 117
  • 166
2
votes
1 answer

Why doesn't the java compiler recognise fields have been initialized?

Suppose I have the following piece of code int myVar; final boolean condition = ; if (condition) { myVar = 1; } if (condition) { System.out.println("myVar = " + myVar); } When I compiled this, I got the expected myVar might not…
2
votes
1 answer

Why JavaCompiler is slow while instantiating a Java class?

I'm using JavaCompiler to dyamically create a Java class, compile it and load in my application. My problem is the following: the execution time with JavaCompiler is much slower than the standard way to instantiate the same class. Here an…
user7486618
2
votes
2 answers

How to get list of class files generated by JavaCompiler compilationTask?

I am trying to compile java code dynamically using javaCompiler. Code works gr8 however I need to get the list of class files created by CompilationTask. Here is source code: JavaCompiler compiler = ToolProvider.getSystemJavaCompiler (); …
sun2
  • 1,118
  • 1
  • 13
  • 17
2
votes
0 answers

generate jar without dependencies

I am generating a jar inside a java program by using the jdk system-compiler. I have some class files which I add into a jar: JarOutputStream target = new JarOutputStream(jarStream, manifest); addClassFilesToJar(new File(classDirectory), target); I…
Gobliins
  • 3,848
  • 16
  • 67
  • 122
2
votes
2 answers

JavaCompiler didn't really compile the class

I want to use reflection to get all the methods of a newly created java class. Like bellow I created the java Class by copying from another file, then I use JavaCompiler to compile the newly created Java. But I don't know why the target class file…
leo
  • 583
  • 2
  • 7
  • 20
2
votes
1 answer

Java: Compile code at runtime on a jre

I need to compile some code in java while runtime. I looked up this and it looks like the way to do it. So far so good but I need to run the final program on every platform. So I'm getting in troubles if there is a system with a jre only. Now I…
H3ADLESS
  • 83
  • 1
  • 10
1
vote
1 answer

Java Error: Could not find or load main class, Caused by: java.lang.NoClassDefFoundError

Compiled I've compiled the java code, but I'm not able to run it. I compiled the code with the following: javac -cp "streamer-client-java.jar:kafka-clients-3.4.0.jar:snappy-java-1.1.10.0.jar:lz4-java-1.8.0.jar:slf4j-api-2.0.7.jar:."…
1
vote
1 answer

compileDebugJavaWithJavac' task (current target is 18) and 'kaptGenerateStubsDebugKotlin' task (current target is 19)

compileDebugJavaWithJavac' task (current target is 18) and 'kaptGenerateStubsDebugKotlin' task (current target is 19) jvm target compatibility should be set to the same Java version. Doesn't Java have backward compatibility? because of a library I…
yardımcı Etis
  • 140
  • 2
  • 12
1
vote
0 answers

"Package Doesn't Exist" - Error if I try to include a JAR-File [java compiler]

My problem is the following: I am sort of new to programming and I wanted to include the guava.jar file I found on the internet (to use the ImmutableList.copyof()-method). I also have additional packages that I want to include (I wrote a few classes…
OleOle
  • 11
  • 2
1
vote
2 answers

Can a Scala compiler plugin transform the autogenerated accessor methods of scala case classes?

After the parser phase of the Scalac process, the following case class case class ExampleCaseClass(var s:String, var i:Int) extends ContextuallyMutable takes the intermediate form: Clazz(case class ExampleCaseClass extends ContextuallyMutable with…
1
vote
1 answer

Compiling Java file with Jar dependencies using command prompt in windows

I have a java file with jar dependencies an I would like to compile them using command in command prompt from windows PC. I have placed all 3 jar files and java file in same folder of D drive. Do i need to set class path in environmental…
nitesh
  • 11
  • 3
1
vote
1 answer

Unwanted import added by compiler

I need the same code to work on different servers with different libraries. So for example serverB contains libraryB. ClassB while serverA doesn't. To make the code work on both servers I do not import the class explicitly but I declare it only when…
M_M
  • 11
  • 2
1
vote
0 answers

java-compiler throws error while compiling code inside a fat jar

I have a spring boot application generating code dynamically at runtime and then compiling when the application is run. When App is run in IntelliJ the generated code is compiled without any errors but when I create a fat jar and generate and…
arshid dar
  • 1,355
  • 2
  • 15
  • 23
1
vote
0 answers

How to include internal dependencies in a Maven project using JavaCompiler API?

I am using JavaCompiler API to compile a string representation of an existing java class in a Maven project. Yet, I'm getting a linker error due to internal dependencies and I'm not sure how to include internal dependencies in the compilation…
OBezzad
  • 145
  • 1
  • 9
1 2
3
9 10