0

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.xmls 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 apps. 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

  1. Resources from shared_code are automagically deployed and made available to the apps. For bonus points, can the apps override the resources somehow?
  2. How do I create a single jar file rather than a jar with a subfolder full of dependencies?
  3. 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.

Andrew Parker
  • 1,425
  • 2
  • 20
  • 28

1 Answers1

1
  • For the shared resources I would use Maven Remote Resources Plugin
  • For creating a jar containing other dependencies & being executable you would need to create a so called Fat Jar

This should give you some hint on how to achieve your goals. To explain everything in the answer would explode the topic I think.

Maybe you can ask followup question regarding the two topics as a separate if you need further help besides the hints I gave.

Community
  • 1
  • 1
JDC
  • 4,247
  • 5
  • 31
  • 74
  • Thanks. This is just the sort of answer I like. I just need a point in the right direction :) Will look into this and get back with comments or more questions. – Andrew Parker Apr 07 '17 at 14:23