My Maven project has two properties which are used when filtering a persistence configuration file:
<database-url>jdbc:mysql://localhost/${database-name}?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;rewriteBatchedStatements=true&amp;useServerPrepStmts=false&amp;useCursorFetch=true</database-url>
<test-database-url>jdbc:mysql://localhost/${test-database-name}?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;rewriteBatchedStatements=true&amp;useServerPrepStmts=false&amp;useCursorFetch=true</te开发者_如何学JAVAst-database-url>
The properties need to be doubly-XML-encoded since the configuration file itself is an XML document and Maven resolves XML entities during resource filtering.
I'd like to be able to run my tests directly from my IDE, so I created a profile and set one property to another.
<database-url>${test-database-url}</database-url>
The problem is that Maven resolves the entities in the setting of the property, and then again during the filtering of the configuration file, which means that my configuration file is invalid XML.
Is there a way to set one property to another without resolving the XML entities?
Not a direct answer but... why don't you use different values for the same property depending of the profile. For example, a (default) development profile would have:
<database.url>jdbc:mysql://localhost:3306/app_dev</database.url>
And a test profile would have:
<database.url>jdbc:mysql://localhost:3306/app_test</database.url>
And if this is not what you want, maybe having a single database.url
property for the url and passing a system property like -Ddatabase-name=app_xxx
for the name would do the trick.
But I may be missing something.
精彩评论