简体   繁体   中英

how to reconcile maven development directory structure to maven release directory structure

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)

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.

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 ).

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM