0

I use standard maven directory structure for my project http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html

However, this is problematic because configuration files are going to be in jar file. There is some discussion on reading the config files from predefined location as How to get the path of a running JAR file?

But I am trying to package my jar file without any configuration files in it and make the directory structure look similar to any other open source projects that we download

project|
        --lib
       |
        --conf
       |
        --docs
       |
        --src

I prefer not to do any source code changes (ex:all my config files are in source path for maven development and I just read the files directly without prepending with the path); if I have to change path to config files in source code, what should I do to make the path work both in development and in production My questions

1)how can I have current "development" directory structure as is, but have my "production" release directory will look similar to that of any apache(say) project

2)for every release, what changes should I do in pom.xml so that the version numbers are appended to jar and incremented

I prefer not to do any source/java code changes (ex:all my config files are in source path for maven development and I just read the files directly without prepending with the path); if I have to change path to config files in source code, what should I do to make the path work both in development and in production

(I am using Maven and Eclipse)

Community
  • 1
  • 1
kashili kashili
  • 955
  • 4
  • 15
  • 31

3 Answers3

1

In my projects I use the maven assembly plugin to package the application in a redistribuable way :

Everything under src/main/java and src/main/resources is packaged inside the main jar (standard behaviour).

Then using assembly plugin, I create a zip containing 3 folders :

  • /lib : contains the main jar + all the dependencies
  • /bin : contains the additional files from the src/main/scripts maven source folder (startup shell scripts)
  • /etc (or /conf) : contains the additional files from the src/main/config maven source folder (config files)

I find this setup very convenient as it is really close to the initial maven standard layout (src/main/java + src/main/resources in the main jar and other folders taken appart), still being adapted to my projects.

superbob
  • 1,628
  • 13
  • 24
  • How do you add version number to the release? Not sure how maven release if maven release can be used for directory structure http://maven.apache.org/guides/mini/guide-releasing.html (I am newbie ) – kashili kashili Jun 02 '14 at 23:50
  • 1
    @kashili kashili, release numbers should be appended automatically to the artifact filename using assembly plugin. The version number is the one in your pom – superbob Jun 03 '14 at 05:50
0

You can use your existing resources by mentioning those resource directories in Maven Resource Plugin.

add following code to build ( tag )section of your pom.xml

<resources>
 <resource>
   <directory>[your folder here]</directory>
 </resource>
</resources>

you can add several non maven standard resources over here ( anything other that src/main/resources ).

Pramod S. Nikam
  • 4,271
  • 4
  • 38
  • 62
0

I want to share some more tips based on what I digged out (@superbob gave good explanation). This is easier said than done....

I wanted to create jar (executable first) and copy this jar file into zip (along with few other directories for releasing in to production)...it is easy if u can look at existing pom file than fiddling with existing pom.

Look here for an existing project(pom.xml) http://www.petrikainulainen.net/programming/tips-and-tricks/creating-a-runnable-binary-distribution-with-maven-assembly-plugin/

In my case, I had multiple pom files and it adds another layer of complexity for newbie like me..look here for multi module example with maven assembly plugin http://maven.apache.org/plugins/maven-assembly-plugin/examples/multimodule/index.html

Last but not least, run the following command to make sure assembly is created

   mvn  clean install package assembly:single
kashili kashili
  • 955
  • 4
  • 15
  • 31