문제

I'm working on a modular maven project. The skeleton of my project is the following:

|-- parent
    |-- model
        --pom.xml
    |-- services
        --pom.xml
    |-- web-app
        --pom.xml

In the model module I have the persistence.xml file with some property references:

<persistence>

<persistence-unit name="myUnit">

    //Some classes definition

  <properties>

     <property name="javax.persistence.jdbc.driver" value="${db.driverClass}" />
     <property name="javax.persistence.jdbc.url" value="${db.connectionURL}" />
     <property name="javax.persistence.jdbc.user" value="${db.username}" />
     <property name="javax.persistence.jdbc.password" value="${db.password}" />

  </properties>


</persistence-unit>

and I enable the resources filtering in the model's pom.xml through

 <build>
    <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
    </resources>
</build>

Now I should want to define a profile in the web-app's pom.xml

<profiles>
 <profile>
        <id>Development</id>
        <properties>
            <db.driverClass>MyDriver</db.driverClass>
            <db.connectionURL>jMyUrl</db.connectionURL>
            <db.username>MyUsername</db.username>
            <db.password>MyPassword</db.password>
        </properties>
    </profile>
 </profiles>

<!-- To launch embded jetty server -->
<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>${maven-jetty-plugin.version}</version>
</plugin>

and replacement the references with the values when I run "mvn jetty:run -P Development". But this not work.

How can I do to solve it?

도움이 되었습니까?

해결책

Maven uses a hierarchical approach.
This means that profiles are only active in the module they are defined and their children. Same goes for properties.
In your case, your file to filter is in a sibling module of the one you are defining the properties. Therefore they are not propagated to the model module

다른 팁

mvn jetty:run does not copy your resources, and thus does not filter. It is mainly designed to work in conjunction with an IDE, i.e. you change something, the IDE compiles/copies your changes.

If you call it from the console, you need to explicitly run the lifecycle (or at least the process-resources phasein your case).

So try something like

mvn process-classes jetty:run

Ideally, you could split the execution into two separate shells, one running jetty:run and the other running mvn process-classes on demand.

Or use an IDE.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top