Ross
Ross

Reputation: 1

How to substitute a variable with real value in a xml file , which is in another dependency jar file by Maven

We have a project called web-app1 and has a dependency on another jar file called core-app.jar which is provided by another team as a shared library , yet there is a hibernate.cfg.xml in this core-app.jar (inside of the jar), with content as below.

<hibernate-configuration>
    <session-factory>
        <property name="dialect">${hibernate.dialect}</property>
        <property name="query.substitutions"><![CDATA[false 'N', true 'Y']]></property>
        <property name="show_sql">false</property>
        <property name="format_sql">false</property>
        <property name="use_sql_comments">false</property>
        <property name="generate_statistics">true</property>
        <property name="hibernate.connection.release_mode">after_transaction</property>
       <!-- Search Configurations -->
        <property name="hibernate.search.default.directory_provider">org.hibernate.search.store.FSDirectoryProvider</property>
        <property name="hibernate.search.default.indexBase">${lucene.index.home}</property>
        <property name="hibernate.search.default.batch.merge_factor">10</property>
        <property name="hibernate.search.default.batch.max_buffered_docs">10</property>
    </session-factory>
</hibernate-configuration>

As we see in the Search Configurations section, there is a variable ${lucene.index.home} that should be replaced by other projects on different OS platform,
so the question, does maven provide a way to filter a dependency jar file and filter the content? any plugins ? war:war , unzip ? dependencies ? I couldn't figure a fast way to do that. it looks to me , no matter what plugin would be adopted, the plugin needs to do 4 things basically.

did anyone run into this similar requirement before.

thanks

Upvotes: 0

Views: 1026

Answers (2)

Chad Wilson
Chad Wilson

Reputation: 121

If you really really REALLY have to do filtering at build time for configuration purposes, those configuration files should be filtered, NOT your dependencies. Then, you should either bundle said file into multiple artifacts (assuming of course you are targeting multiple environments), or be provided outside the built artifact as an externalized resource.

Upvotes: 0

Robin
Robin

Reputation: 24262

I would assume that those values are meant to be set at runtime, likely as VM arguments. It doesn't make sense to provide a jar file that has to be modified to be able to be used.

Upvotes: 1

Related Questions