简体   繁体   English

Maven pom.xml文件如何将配置转换为系统属性?

[英]How maven pom.xml file convert configurations into system properties?

As we all know, suppose we define 'transportation' in pom.xml in maven, after we run command like 'mvn jetty:run' the property 'db.name' can be discovered by other configuration, like 'hibernate.cfg.xml'. 众所周知,假设我们在maven的pom.xml中定义了“ transportation”,在运行诸如“ mvn jetty:run”之类的命令后,属性“ db.name”可以通过其他配置(例如“ hibernate.cfg.xml”)发现'。 That's fine. 没关系。

But now, I configure this project to run on tomcat directly , by 'run on server' from eclipse, instead of by maven command. 但是现在,我将该项目配置为直接通过Eclipse中的“在服务器上运行”而不是通过maven命令在tomcat上运行。 (I did this by configure a project facets in eclipse, make it can use 'run on server' menu). (我通过在eclipse中配置项目构面来做到这一点,使其可以使用“在服务器上运行”菜单)。 You can see now I just run with eclipse, nothing to do with 'maven' or 'pom.xml', but it still use properties like 'db.name'. 您现在可以看到我只使用eclipse运行,与'maven'或'pom.xml'无关,但是它仍然使用'db.name'之类的属性。 If I need change to another db, I had to change the 'db.name' property, then run some command in maven to make it take effect. 如果需要更改为其他数据库,则必须更改'db.name'属性,然后在maven中运行一些命令以使其生效。

Can any body give some explanation about how it works? 任何机构都可以对其工作方式进行一些解释吗? Does maven command generate some file at some place that takes the properties? maven命令是否在带有属性的某个位置生成一些文件?

Properties are set for virtual machine. 为虚拟机设置属性。 Maven run new/existing (dependent on configuration) instance of runtime environment. Maven运行运行时环境的新/现有(取决于配置)实例。 So you can pass properties as 因此您可以将属性传递为

-Dkey=value (or <key>value</key> in pom) -Dkey=value (或pom中的<key>value</key>

Check in eclipse configuration if you can pass arguments when you run tomcat? 检查eclipse配置是否可以在运行tomcat时传递参数?

Eclipse maven plugin (from Eclipse foundation) understands the pom.xml and usually syncs with any changes. Eclipse maven插件(来自Eclipse Foundation)理解pom.xml并通常与任何更改同步。

But sometimes I observed that it goes out of sync, and to fix that problem I need to delete the temporary folders/files created by Eclipse (.settings, .classpath and .project) and import again. 但是有时我发现它不同步,并且要解决该问题,我需要删除Eclipse创建的临时文件夹/文件(.settings,.classpath和.project),然后再次导入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM