在我們的項目中,我需要從build.properties中將一些值提取到persistence.xml。請讓我知道是否有任何可能的方法?如何從build.properties獲取值到persistence.xml?
2
A
回答
0
例如:build.properties包含
username = root
password = shoot
爲屬性,那麼你可以改變的persistence.xml有像
<username>@[email protected]</username>
<password value="@[email protected]"/>
值,那麼你的build.xml應該是這樣的意志工作。
<target name="replace">
<property file="build.properties"/>
<replace file="persistence.xml" token="@[email protected]" value="${username}"/>
<replace file="persistence.xml" token="@[email protected]" value="${password}"/>
</target>
這裏$ username和$ password值自動螞蟻從<property>
標籤標識,你可以用鑰匙作爲名稱訪問值。
0
我不得不回憶一下自己。這樣做的正確的方法是這樣的
Map<String, String> props = new HashMap<String, String>();
props.put("hibernate.connection.username", "sa");
props.put("hibernate.connection.password", "");
props.put("hibernate.connection.url", "jdbc:h2:mem:test_mem;MVCC=true");
EntityManagerFactory factory = Persistence.createEntityManagerFactory("inmemory", props);
可以代替硬編碼的用戶名和我一樣有暫時從你的build.properties文件閱讀。玩的開心。
院長
相關問題
- 1. 從POJO讀取persistence.xml
- 2. 如何從persistence.xml中獲取spring的數據源配置?
- 3. 如何從HTML獲取價值到Suitescript?
- 4. 如何從MessageHeaderInfo獲取值
- 5. 如何從XML獲取值
- 6. 如何從Arraylist獲取值?
- 7. 如何從MyBatis獲取值?
- 8. 如何從ActionListener獲取值
- 9. 如何從timedelta獲取值?
- 10. 如何從json獲取值
- 11. 從TextBox獲取值到URL
- 12. 從ruby獲取值到javascript
- 13. 從行獲取值到列
- 14. 如何從WCF獲取,設置和返回值中獲取值?
- 15. 如何從停止可觀察到的價值獲取價值
- 16. 如何從EditText從片段獲取值到活動?
- 17. 如何測試是否找到persistence.xml?
- 18. izpack和build.properties
- 19. build.properties和build.xml
- 20. 如何根據build.properties中的值配置hibernate.cfg.xml,struts.xml,MessageResources.properties
- 21. 從tomcat加載persistence.xml
- 22. tomcat如何利用build.properties和build.xml?
- 23. 如何從ListArray獲取數據(鍵值)
- 24. 如何從屬性表中獲取值
- 25. 如何從MemberExpression獲取屬性值
- 26. 如何從PHP中獲取Android的值
- 27. 如何從Coldfusion獲取HTTP標頭值?
- 28. 如何從服務中獲取值?
- 29. 如何從Dijit.Editor獲取價值?
- 30. 如何從php數組中獲取值
我怎麼可以將build.properties的值注入到persistence.xml?這些鏈接沒有顯示persistence.xml。當build.xml正在運行時,我需要從build.properties獲取值到persistence.xml ....這意味着值應該自動在persistence.xml中反射... – user1340856 2012-04-24 07:29:06
請通過替換值與Ant任務鏈接這樣做。 – Phani 2012-04-24 07:32:34
對不起。我沒有從這個鏈接得到任何想法。這個標籤實際上做了什麼? –
user1340856
2012-04-24 07:39:01