I'm trying to do a modular application, and I'm having a problem because I have two modules, where one of them depends on the other.
For example: module 1 has a class that imports classes from module 2.
I've put the following line in my Manifest.txt of module 1:
Class-Path: modulo_2.jar
... but I'm getting a error when I create the jar because I can't resolve the import of the classes from the module 2 that I need in the module 1. Despite the errors the jar is being created. After I deploy the project, I still have the same error saying that my classes can't resolve the imports, anyone have any idea on how can I make this work.
When you are building the jar (compile time) the module_2.jar should be in the class path. You need to build module_2.jar first and add it to the classpath. If you are using the command line to build:
javac -cp module_2.jar my_java_files
In run time, the module_2.jar must be in the location you've instructed it in the manifest file. If you've used Class-Path: module_2.jar, then place module_2 in the same folder as module_1 and run it like this:
java -jar module_1.jar MyMainClass
或者,您可以尝试使用具有非常好的依赖项管理的Maven2进行构建,而不是自己弄乱清单,并使用Assembly插件来构建可分发的tar.gz,在其中将其依赖项与应用程序一起交付。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.