0

I have dev/XYZ.properties file, i am building a jar file using maven -P dev install. How can I place the property file in child.jar/META-INF/XYZ.properties file

user665837
  • 345
  • 1
  • 3
  • 7

1 Answers1

0

You have to execute the maven-resources-plugin:copy-resources goal for your profile dev and bind it with the appropriate phase (process-resources seems the best phase to me). Here is how to define your profile dev :

<profile>
  <id>dev</id>
  ...
  <build>
     <plugins>
        <plugin>
           <artifactId>maven-resources-plugin</artifactId>
           <version>2.6</version>
           <executions>
             <execution>
               <id>copy-resources</id>
               <phase>process-resources</phase>
               <goals>
                 <goal>copy-resources</goal>
               </goals>
               <configuration>
                  <outputDirectory>${basedir}/target/classes/META-INF</outputDirectory>
                  <resources>          
                    <resource>
                       <directory>${basedir}/dev</directory>
                       <includes>
                         <include>XYZ.properties</include>
                       </includes>
                    </resource>
                   </resources>              
               </configuration>            
            </execution>
         </executions>
     </plugin>
   </plugins>
</build>
ben75
  • 29,217
  • 10
  • 88
  • 134
  • Thanks for the code, i can deploy properties file on child level based on profile. If I run test profile, child-test.jar is deployed as expected. And now if I want build a war file from parent project, if I want to run a dev profile, I am getting parent-dev.war, child-jat inside jar is still child-test.jar. Is this how it is expected. If I want all dev profiles in my wars and jar file, waht I need to do, Can you please advise – user665837 Mar 25 '13 at 15:05
  • you're welcome. don't hesitate to upvote and accept my answer... that's the way it goes on stackoverflow (http://stackoverflow.com/about) – ben75 Mar 25 '13 at 15:09
  • if i run dev profile on parent project, i am not getting dev profiles on child dev profiles, if my target folder in my eclipse is not empty, is there any way in maven i can overcome this issue ie., if I run dev profile on parent project, all my parent and child projects should get values based on profile that I run for example dev in this case. – user665837 Mar 25 '13 at 15:14
  • Normally the profile also apply to child modules. Did you run maven from command line ? (maven-eclipse integration is full of bugs). – ben75 Mar 25 '13 at 15:20
  • yeah I ran from command line. What I did was 1) child project tried to install mvn install -Ptest --- jar has test profile settings 2) parent project tried mvn install -Pdev --- war has dev profile settings but inside war, jar file has test profile settings – user665837 Mar 25 '13 at 15:26
  • Is your jar project referenced in the parent with this kind of entry : `path_to_jar_project ? If not: then the child won't be build with it's parent (and so you get the latest build of the jar from your local repo, and it's the jar build with the test profile). Maybe ask another question because it's getting more complex here... – ben75 Mar 25 '13 at 15:38
  • thanks ben, we have module settings one level up beacuse of different projects, thanks for quick replyy:) – user665837 Mar 25 '13 at 15:56