JLang icon indicating copy to clipboard operation
JLang copied to clipboard

How to compile a project with an external package?

Open gmy2013 opened this issue 3 years ago • 4 comments

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?

gmy2013 avatar Sep 06 '20 15:09 gmy2013

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

andrewcmyers avatar Sep 06 '20 16:09 andrewcmyers

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!

gmy2013 avatar Sep 07 '20 04:09 gmy2013

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

Prokksi avatar Sep 30 '20 16:09 Prokksi

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.

dz333 avatar Nov 03 '20 03:11 dz333