2017-04-12 43 views
1

在我的项目,在捆绑模块,在resource目录,我有我的示例startup.cfg文件。该文件包含我想在启动时使用的属性。在捆绑pom.xml我有以下。创建配置文件在Maven安装和没有或之前功能安装为Karaf

<build> 
    <plugins> 
    <plugin> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>build-helper-maven-plugin</artifactId> 
     <executions> 
     <execution> 
      <id>attach-artifacts</id> 
      <phase>package</phase> 
      <goals> 
      <goal>attach-artifact</goal> 
      </goals> 
      <configuration> 
      <artifacts> 
       <artifact> 
       <file>${project.build.directory}/classes/startup.cfg</file> 
       <type>cfg</type> 
       <classifier>config</classifier> 
       </artifact> 
      </artifacts> 
      </configuration> 
     </execution> 
     </executions> 
    </plugin> 
    </plugins> 
</build> 

而在我的功能XML,我有,

<feature name="my-sample-feature" description="Sample service" version='${project.version}'> 
    <bundle>mvn:org.sample.app/service.implementation/{{VERSION}}</bundle> 
    <configfile finalname="/etc/org.sample.app.startup.cfg">mvn:mvn:org.sample.app/service.implementation/{{VERSION}}/cfg/config</configfile> 
</feature> 

在功能XML,我已经加入,

<dependency> 
    <groupId>${project.groupId}</groupId> 
    <artifactId>service.implementation</artifactId> 
    <version>${project.version}</version> 
    <classifier>config</classifier> 
    <type>cfg</type> 
</dependency> 

此功能启动功能了。现在,当我将该功能安装在卡拉服务器中时,或者在此情况下,当我旋转卡拉夫时,只有etc/org.sample.app.startup.cfg被创建。我的目标很简单,就是让这个conf文件始终在etc/之间,独立于安装的功能。

+0

我不明白。当你启动karaf功能安装,但配置文件没有创建?您发布的功能似乎格式错误,您是否可以粘贴部署到您的Maven存储库的feature.xml的确切内容? –

+0

也许Maven程序集插件可以帮助(http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html) –

回答

0

安装该功能时,cfg文件将部署到etc文件夹中。如果你希望它独立于该功能安装或不安装,这意味着你必须手动将它部署到等等,这是更简单的后,将cfg附加到你的工件,就像你在你的pom中做的那样。

请记住,如果您想遵循最佳实践(特别是在生产环境中),请勿将cfg部署与其原始功能分开。