0

Does anyone know of a library or any ways to compile Java Source Code in a Java Application (I know its pretty confusing)

So I have some source code files like me.user.testapp.Main and me.user.testapp.Settings I want it so you have a Java Application with a GUI that has some parameters to config the settings. When you click 'Compile' it should compile the source code files into a .jar file but I can't seem to find any tools that has a compiler library or so to use in my code to compile source code files. Is that possible? And if it is can someone give me a hint on how to do it. Thank you.

  • You could just make use of `ProcessBuilder` to run the external commands, for [example](https://stackoverflow.com/questions/28955020/compiling-and-executing-using-exec-in-java-fails-using-command-that-works-from-t/28955036#28955036) and [example](https://stackoverflow.com/questions/15218892/running-a-java-program-from-another-java-program/15220419#15220419) – MadProgrammer Sep 19 '22 at 02:03
  • Or you could take a deep dive into `JavaCompiler` class, for [example](https://stackoverflow.com/questions/21544446/how-do-you-dynamically-compile-and-load-external-java-classes/21544850#21544850) and [example](https://stackoverflow.com/questions/25090434/how-to-compile-and-run-inside-the-java-program/25090801#25090801) and [example](https://stackoverflow.com/questions/25177372/how-to-get-the-output-of-a-java-program/25177554#25177554) – MadProgrammer Sep 19 '22 at 02:04
  • Java also has support for reading/writing Jar files via the `java.util.jar` classes – MadProgrammer Sep 19 '22 at 02:06
  • Thank you I didn't know of the JavaCompiler class. That is all I needed, thanks. – CustomPayload Sep 19 '22 at 02:08

0 Answers0