tags:

views:

226

answers:

2

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.

+2  A: 

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
kgiannakakis
A: 

Alternately, instead of messing about with manifests yourself, you could try building with Maven2, which has very nice dependency management, and use the assembly plugin to build a distributable tar.gz in which to ship your application with its dependencies.

Ben Hardy