在我们的项目中,我需要从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. 从persistence.xml获取值
- 2. 从POJO读取persistence.xml
- 3. 如何从persistence.xml中获取spring的数据源配置?
- 4. PHP如何从javascript获取值到php
- 5. 如何从XML获取值到int
- 6. 如何从HTML获取价值到Suitescript?
- 7. 如何从HashMap获取值?
- 8. 如何从XML获取值
- 9. 如何从ActionListener获取值
- 10. 如何从HttpRequest获取值?
- 11. 如何从MessageHeaderInfo获取值
- 12. 如何从json获取值?
- 13. 如何从datetimepicker获取值
- 14. 如何从Dijit.Calendar获取值?
- 15. 如何从MyBatis获取值?
- 16. 如何从Arraylist获取值?
- 17. 如何从json获取值
- 18. 如何从timedelta获取值?
- 19. 如何从XML获取值
- 20. 如何从simplexml_load_file获取值?
- 21. 如何从textarea获取值
- 22. 获取maven以取代基于用户/ build.properties
- 23. 从TextBox获取值到URL
- 24. 从ruby获取值到javascript
- 25. 从行获取值到列
- 26. 从mysql获取值到xml
- 27. 如何从WCF获取,设置和返回值中获取值?
- 28. 如何从persistence.xml引用外部hibernate.cfg.xml
- 29. 如何修改属性从persistence.xml中
- 30. 如何从命令行获取值到php(2值)
我怎么可以将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