polyglot-compiler / JLang

JLang: Ahead-of-time compilation of Java programs to LLVM
http://polyglot-compiler.github.io/JLang/
Other
287 stars 30 forks source link

How to compile a project with an external package? #68

Open gmy2013 opened 4 years ago

gmy2013 commented 4 years ago

Hello, thanks for your great job! I have a question on the compilation of Jlang. Since JLang cannot link pre-compiled JAR files, how to compile a project or single java file with a package such as "import org.dom4j.XXX", which is not included in JDK directory?

andrewcmyers commented 4 years ago

If you have the source for the package, you can compile it using JLang and then link against it.

gmy2013 commented 4 years ago

Thanks for your reply! Since I am not familiar with the components of Jlang, could you please explain it in detail? What is the form of the "source for the package", .java files? How to compile the package using JLang, using the " Building Larger Project " example or re-writing the Makefile to add the packages to JDK? And how to link against the compiled package? Thank you very much!

Prokksi commented 4 years ago

Hi @gmy2013 , did you make any progress in the meantime? I am interested in this usecase as well.

dz333 commented 3 years ago

At the moment, JLang can only link against standalone dynamically linked libraries. Normal java projects are not standalone libraries as they are bytecode that can be executed only inside a JVM.

If you have the original java source files as a project, then you can compile them using JLang with the "Building Larger Project" example as a starting point. This will produce a dynamically linked library that you can then link against once you have built your original project using JLang.

Note that ALL source files need to be compiled this way, so if your dependency has dependencies, those will also need to be compiled similarly. Obviously this is not tenable for large java projects that import many dependencies but at the moment we do not have a better solution.

In the future, we would like to add a feature where JLang could compile Java bytecode, which would solve many of these problems since we could compile JARed dependencies along with your source code.