Maven的配置文件和安装 [英] Maven profiles and install
问题描述
如果我有Maven的构建设置与设置了不同的环境配置文件的应用程序(说喜欢督促与开发,定义不同的DB设置和类似的东西)的安装的目标似乎并没有什么意义,因为我不知道哪个环境得到了安装到我的回购 - 我刚刚拿到了com.example.myproject:MyApp的:0.0.1
If I have Maven builds set up for an app with profiles set up for different environments (say like prod vs. dev, defining different DB settings and stuff like that) the 'install' goal doesn't seem to make sense, as I don't know which environment got installed into my repo - I've just got com.example.myproject:myapp:0.0.1.
我有误解的东西,或者是应该与其他目标可以使用配置文件?
Have I misunderstood something, or are profiles supposed to be used with other goals?
推荐答案
好了,你可以让每个配置文件创建了分类,即一个罐子使用分类
属性独特的罐子为每个环境。这里是一个code片段来说明这一点。当与开发
配置文件( MVN -P dev的安装
)运行时,它会创建 -dev
分类,如的myapp-DEV-0.0.1.jar
Well, you could use the classifier
attribute so that each profile creates a jar with the classifier, i.e. a unique jar for each environment. Here is a code snippet to illustrate this. When run with the dev
profile (mvn -P dev install
), it creates a jar with -dev
classifier, like myapp-dev-0.0.1.jar
<project>
...
<properties>
<env></env>
</properties>
...
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classifier>${env}</classifier>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
...
<profile>
<id>dev</id>
<properties>
<env>dev</env>
</properties>
...
</profile>
</profiles>
</project>
这篇关于Maven的配置文件和安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!