ODL中如何将配置文件打包到运行目录下
2017-12-02 14:57
344 查看
目录结构
config
|----src
| |----main
| |----java
| |----resource
| | |----initial
| | | |----config-example.xml
| | |----org.opendaylight.blueprint
| | |----config-blueprint.xml
| | ----yang
| |----example-config.yang
|----pom.xml
feature
|----src
|----main
|----features
|----feature.xml
[[pom.xml]]
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.opendaylight.controller</groupId>
<artifactId>config-parent</artifactId>
<version>0.6.0-Carbon</version>
<relativePath/>
</parent>
<groupId>org.exampleproj</groupId>
<artifactId>config</artifactId>
<version>1.0.0</version>
<name>ODL :: org.exampleproj :: ${project.artifactId}</name>
<packaging>bundle</packaging>
<dependencies>
...
</dependencies>
<!--build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>
org.exampleproj.config.*,
org.opendaylight.yang.gen.v1.urn.exampleproj.config.example.config.rev171202.*
</Export-Package>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>attach-artifacts</id>
<goals>
<goal>attach-artifact</goal>
</goals>
<phase>package</phase>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/classes/initial/example-config.xml</file>
<type>xml</type>
<classifier>config</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build-->
</project>
[[example-config.yang]]
module example-config {
yang-version 1;
namespace "urn:exampleproj:config:example-config";
prefix "example-config";
revision "2017-12-02" {
description "example config test";
}
container example-config {
leaf name {
type string;
}
leaf location {
type string;
}
}
}
[[config-example.xml]]
<example-config xmlns="urn:exampleproj:config:example-config">
<name>helloworld</name>
<location>overseas</location>
</example-config>
[[config-blueprint.xml]]
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
odl:use-default-for-reference-types="true">
<odl:clustered-app-config id="exampleConfig"
default-config-file-name="example-config.xml"
binding-class="org.opendaylight.yang.gen.v1.urn.exampleproj.config.example.config.rev171202.ExampleConfig">
</odl:clustered-app-config>
</blueprint>
[[feature.xml]]
...
<feature name='odl-exampleproj-config' version='${project.version}' description='OpenDaylight :: exampleproj :: exampleconfig'>
<configfile finalname="etc/opendaylight/datastore/initial/config/example-config.xml">mvn:org.exampleproj/config/{{VERSION}}/xml/config</configfile>
<bundle>mvn:org.exampleproj/config/{{VERSION}}</bundle>
</feature>
...
如果不想把配置数据嵌入到config-blueprint.xml的<![CDATA[ 和 ]]>,那么就把配置文件写到example-config.xml中
当程序编译之后,在karaf/target/assembly/etc下没有产生opendaylight目录
当程序运行的时候会生成这个目录karaf/target/assembly/etc/opendaylight/datastore/initial/config, 并且把example-config.xml拷贝到这个目录下
当在pom.xml中加入了controller的config-parent之后,pom.xml中的build部分注释了,example-config.xml在运行的时候是出现在想要的目录中的,所以这段注释的并没有什么影响。绿色的部分可能跟build中定义的绿色部分有关吧,存疑。
如果只是修改配置文件,如何更新配置文件测试呢?
如果配置文件在<![CDATA[ 和 ]]>里面,只要替换karaf/target/assembly/system/org/exampleproj/config/1.0.0/config-1.0.0.jar包,重启karaf即可
如果配置文件已经在一个单独的文件中,并且声明了最终的文件位置是etc/opendaylight/datastore/initial/config/example-config.xml
那么需要修改karaf/target/assembly/system/org/exampleproj/config/1.0.0/config-1.0.0-config.xml,或者说覆盖此文件,
然后删掉karaf/target/assembly/etc下的opendaylight目录,如果不删掉,就不会更新,如果删掉,会把karaf/target/assembly/system/org/exampleproj/config/1.0.0/config-1.0.0-config.xml文件拷贝到etc相应的目录重命名成我们想要的文件。
参考文档
https://wiki.opendaylight.org/view/Using_Blueprint#Using_the_Datastore
http://blog.csdn.net/sonycong/article/details/49863915
config
|----src
| |----main
| |----java
| |----resource
| | |----initial
| | | |----config-example.xml
| | |----org.opendaylight.blueprint
| | |----config-blueprint.xml
| | ----yang
| |----example-config.yang
|----pom.xml
feature
|----src
|----main
|----features
|----feature.xml
[[pom.xml]]
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.opendaylight.controller</groupId>
<artifactId>config-parent</artifactId>
<version>0.6.0-Carbon</version>
<relativePath/>
</parent>
<groupId>org.exampleproj</groupId>
<artifactId>config</artifactId>
<version>1.0.0</version>
<name>ODL :: org.exampleproj :: ${project.artifactId}</name>
<packaging>bundle</packaging>
<dependencies>
...
</dependencies>
<!--build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>
org.exampleproj.config.*,
org.opendaylight.yang.gen.v1.urn.exampleproj.config.example.config.rev171202.*
</Export-Package>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>attach-artifacts</id>
<goals>
<goal>attach-artifact</goal>
</goals>
<phase>package</phase>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/classes/initial/example-config.xml</file>
<type>xml</type>
<classifier>config</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build-->
</project>
[[example-config.yang]]
module example-config {
yang-version 1;
namespace "urn:exampleproj:config:example-config";
prefix "example-config";
revision "2017-12-02" {
description "example config test";
}
container example-config {
leaf name {
type string;
}
leaf location {
type string;
}
}
}
[[config-example.xml]]
<example-config xmlns="urn:exampleproj:config:example-config">
<name>helloworld</name>
<location>overseas</location>
</example-config>
[[config-blueprint.xml]]
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
odl:use-default-for-reference-types="true">
<odl:clustered-app-config id="exampleConfig"
default-config-file-name="example-config.xml"
binding-class="org.opendaylight.yang.gen.v1.urn.exampleproj.config.example.config.rev171202.ExampleConfig">
</odl:clustered-app-config>
</blueprint>
[[feature.xml]]
...
<feature name='odl-exampleproj-config' version='${project.version}' description='OpenDaylight :: exampleproj :: exampleconfig'>
<configfile finalname="etc/opendaylight/datastore/initial/config/example-config.xml">mvn:org.exampleproj/config/{{VERSION}}/xml/config</configfile>
<bundle>mvn:org.exampleproj/config/{{VERSION}}</bundle>
</feature>
...
如果不想把配置数据嵌入到config-blueprint.xml的<![CDATA[ 和 ]]>,那么就把配置文件写到example-config.xml中
当程序编译之后,在karaf/target/assembly/etc下没有产生opendaylight目录
当程序运行的时候会生成这个目录karaf/target/assembly/etc/opendaylight/datastore/initial/config, 并且把example-config.xml拷贝到这个目录下
当在pom.xml中加入了controller的config-parent之后,pom.xml中的build部分注释了,example-config.xml在运行的时候是出现在想要的目录中的,所以这段注释的并没有什么影响。绿色的部分可能跟build中定义的绿色部分有关吧,存疑。
如果只是修改配置文件,如何更新配置文件测试呢?
如果配置文件在<![CDATA[ 和 ]]>里面,只要替换karaf/target/assembly/system/org/exampleproj/config/1.0.0/config-1.0.0.jar包,重启karaf即可
如果配置文件已经在一个单独的文件中,并且声明了最终的文件位置是etc/opendaylight/datastore/initial/config/example-config.xml
那么需要修改karaf/target/assembly/system/org/exampleproj/config/1.0.0/config-1.0.0-config.xml,或者说覆盖此文件,
然后删掉karaf/target/assembly/etc下的opendaylight目录,如果不删掉,就不会更新,如果删掉,会把karaf/target/assembly/system/org/exampleproj/config/1.0.0/config-1.0.0-config.xml文件拷贝到etc相应的目录重命名成我们想要的文件。
参考文档
https://wiki.opendaylight.org/view/Using_Blueprint#Using_the_Datastore
http://blog.csdn.net/sonycong/article/details/49863915
相关文章推荐
- maven-war-plugin 插件打包时,src/main/java 目录下mybatis的映射文件如何配置
- linux tar (打包.压缩.解压缩)命令说明 | tar如何解压文件到指定的目录?
- 如何把一个java程序打包成exe文件,运行在没有java虚
- 配置《UNIX环境高级编程》中程序的运行环境,解决“apue.h:没有那个文件或目录”错误
- 【maven】如何把配置文件打包到jar中
- 如何用命令打包一个站点,包括其所有目录文件
- (转)WEB程序打包详解:(连接SQL2005数据库,修改配置文件,建立虚拟目录)
- 如何让bat,cmd文件后台运行?如何把文件打包成EXE?
- Linux有问必答:如何修复“运行aclocal失败:没有该文件或目录”
- 【asp】如何打开asp文件,包括IIS安装,HTTP错误403.14,配置默认文档,启用目录浏览
- 【深入JAVA】程序打包成Jar包运行并读取外部配置文件
- Flex 在运行时如何读取配置文件
- 关于Java的socket服务端项目如何打包成exe文件运行在服务器上。
- Eclipse打包jar文件 以及如何运行jar文件
- 教你如何配置Tomcat 绑定指定目录的工程文件
- 如何在eclipse中编写好程序,然后打包成jar文件,在hadoop分布式集群上运行
- 在电脑上找到这个路径:D:\jakarta-tomcat-6\conf\Catalina,将localhost目录直接删除掉,再一运行,就没事了! 因为配置文件中配置了启动程序,而webapps文件夹下却没有此应用程序,所以出现了上述错误。
- 用Nginx如何配置运行无扩展名PHP文件或非.PHP扩展名文件
- asp.net网站运行时,读取的配置文件总是网站根目录的配置文件
- WEB程序打包详解:(连接SQL2005数据库,修改配置文件,建立虚拟目录)