Different files to be packaged in a Maven war project

狂风中的少年 提交于 2019-12-19 04:07:48

问题


I have a war packaging Maven project, in which I have a Java properties files called myapp.properties. In this properties file, I store some parameters, for example, database connection parameters, which will be used by the webapp.

  1. Either in a continuous integration environment or in my development environment, I want to set some testing parameters in myapp.properties to connect to my test database for example.
  2. At the same time, I want to leave these parameters blank in my final war package so that users can add these values by themselves during deployment to their environment. The final war package should be a build artifact generated in the continuous integration environment.

Essentially, there are two versions of myapp.properties file I want to use in different cases. My question is, what is the Maven way to solve this problem? I use Eclipse + WTP + m2eclipse in my development environment, and I hope the solution can works well together with my development tools.


回答1:


You can have a look at this blog: http://blog.jayway.com/2010/01/21/one-artifact-with-multiple-configurations-in-maven/

They build different war-files and use different classifier (instead of different profiles). I am not sure if it is the maven way, but it works for some of my projects.




回答2:


i would try it with

pom.xml for your project (or parent pom)

        <build>
          ...
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.properties</include>
            </includes>
            <filtering>true</filtering>
        </resource>
         ...
        </build>

in your properties file(s) e.g.

db.url=${db.url}

and in your settings.xml (see http://maven.apache.org/settings.html#Profiles)

<db.url>jdbc:mysql://localhost:3306/testdb</db.url>

depending on your development stage (local, build server, etc.) you can use different db.url values

this will not leave the db.url property blank, but each time you package the artifact you dont want it really to stay blank do you ?



来源:https://stackoverflow.com/questions/4216657/different-files-to-be-packaged-in-a-maven-war-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!