我正在尝试部署带有属性的 iPojo 捆绑包。捆绑包如下所示:
@Component
public class Greeter {
@Property(name = "greeting")
private String greeting;
@Validate
public void start() {
System.out.println(greeting);
}
}
pom.xml 看起来像这样:
<groupId>com.example.my</groupId>
<artifactId>osgi-greeter</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.ipojo.annotations</artifactId>
<version>1.12.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!-- BND Maven Plugin Configuration -->
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<!--<Private-Package>$YOUR_PRIVATE_PACKAGE</Private-Package> <Export-Package>$YOUR_EXPORTED_PACKAGE</Export-Package> -->
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-ipojo-plugin</artifactId>
<version>1.12.1</version>
<executions>
<execution>
<goals>
<goal>ipojo-bundle</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
我使用 Apache Felix 作为 OSGi 运行时。我添加了文件安装包并配置了它的路径。在路径中,我添加了 osgi-greeter 包和一个名为 com.example.my.Greeter.cfg 的配置文件,如下所示:
greeting = Hello World
我打开了 Felix 的调试日志,可以看到,fileinstall 包已经加载了它的参数。但是,它什么也没做。我可以手动安装和启动捆绑包,但它显然只向控制台输出 null。目标是添加多个配置文件并让 fileinstall 从它们启动实例。有什么想法可以实现这一点,或者我可以做些什么来使 fileinstall 以这种方式工作?