Reputation: 242
I have a highly modular application that I am trying to build and planning it out in my head is giving me some issues. The application is as follows. I want to create a series of JAR files that contain the business logic for my application, A.jar
, B.jar
and C.jar
.
In addition to these JAR files, I would like to expose each of their functionalities to the Web on a dynamic and per Jar bases. So for instance, I may have A.jar
and B.jar
on a machine, and I would like the ability to deploy A.war
and B.war
into a Tomcat container on the same machine, where A.war and B.war simply use something like Spring to field the HTTP Request and forward this params onto A.jar
and B.jar
.
Questions:
A.war
and B.war
without it failing due to the fact that A.jar
and B.jar
may not be there at the time? A.jar
and B.jar
to the Classpath of Tomcat, but how can I will I be able to build A.war
and B.war
and basically just promise them that the specific Jar files that they need will be there when they go to load classes from it?Any help would be much appreciated, I have been a Java developer for awhile now, but have not delved into super modular code where class paths became an issue until recently.
Upvotes: 3
Views: 1528
Reputation: 27812
how can I will I be able to build A.war and B.war and basically just promise them that the specific Jar files that they need will be there when they go to load classes from it?
This is actually a suitable case for the provided
scope for a Maven dependency. From official documentation:
provided
- this is much likecompile
, but indicates you expect the JDK or a container to provide it at runtime. It is only available on the compilation and test classpath, and is not transitive.
That is, if you had a multi-module Maven project from which you would build A.jar
(e.g. the a-lib module), B.jar
(e.g. the b-lib module), the A.war
(e.g. the a-war module) and B.war
(e.g. the b-war module)
- project
|___a-lib
|___b-lib
|___a-war
|___b-war
the war modules would have dependencies on the library modules but in scope provided
: libraries will be used for compilation and testing, but will not be packed as part of the lib
folder of the war files. They will however need to be present at runtime, as part of the web container classpath.
Provided is normally used with libraries which are provided (that is) out-of-the-box by the host container. A classic example is the Servlet API library: your application depends on it, but it is always provided by the servlet container (i.e. tomcat).
Similarly, you may look at the runtime
scope in case you actually really don't want to use it for compilation (there is no direct reference to libraries code in war modules):
runtime
- this scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath.
Runtime scope is normally used for a driver (like a JDBC driver): something you would not (you shouldn't) refer directly in your code, but you definitely need at runtime. As such, it will be part of the war lib
packaging.
Upvotes: 3