I'm just ramping up on Maven so perhaps somewhat rookie questions. I've found various pieces to my puzzle but yet to find a clear doc on how to achieve the following.
I have some common java code which I want to share between two java applications. I've set this up using maven modules as follows:
Root Dir
pom.xml
shared_code
pom.xml
src
...
app1
pom.xml
src
...
app2
pom.xml
src
...
The pom.xml
file in the dir is simple and mainly consists of
<packaging>pom</packaging>
<modules>
<module>shared_code</module>
<module>app1</module>
<module>app2</module>
</modules>
The pom.xml
in the shared_code
subfolder just uses maven-compiler-plugin
and <packaging>jar</packaging>
to create a jar file.
The pom.xml
s in the app
subfolders use
maven-compiler-plugin
maven-jar-plugin
maven-dependency-plugin
and mark the shared_code
module as a dependency.
This works okay, but I'm failing to achieve some goals. Firstly, my resources are a mess. I can't get resources from the shared_code to automagically be available to the app
s. Secondly, this creates for me a jar
file for each app
which contains only the classes for the app
. In a subfolder (in the generated target
folder) I get all the dependency jars, including the shared_code
one.
Could someone explain how to achieve the following please
- Resources from
shared_code
are automagically deployed and made available to theapp
s. For bonus points, can theapps
override the resources somehow? - How do I create a single jar file rather than a jar with a subfolder full of dependencies?
- How do I create an executable rather than a jar?
For other bonus points, please feel free to tell me I'm approaching the problem in a non-canonical way and completely correct me.