如何启动OSGI-INF蓝图
How to start OSGI-INF blueprint
我是 OSGI-INF 蓝图的初学者。
我有两个 类 命名的帐户和货币。我现在正尝试通过在 IntelliJ 中按 "Run Account SHIFT+F10" 来启动我的程序。然后我就得到了这个:
Hello Account!
但我想让它写 Currency 方法 toString()。
账户:
package com.domain.subdomain;
public class Account {
private Currency currency;
public Account() {
}
public void setCurrency(Currency currency){
this.currency = currency;
}
public static void main(String[] args) {
System.out.println("Hello Account!");
}
}
货币:
package com.domain.subdomain;
public class Currency {
String country;
String isoCode;
String unit;
String name;
double transferPurchase;
double transferSell;
double transferChange;
double transferLast;
double transferDelta;
double notePurchase;
double noteSell;
public Currency(){
}
public Currency(String country, String isoCode, String unit, String name, double transferPurchase, double transferSell, double transferChange, double transferLast, double transferDelta, double notePurchase, double noteSell) {
this.country = country;
this.isoCode = isoCode;
this.unit = unit;
this.name = name;
this.transferPurchase = transferPurchase;
this.transferSell = transferSell;
this.transferChange = transferChange;
this.transferLast = transferLast;
this.transferDelta = transferDelta;
this.notePurchase = notePurchase;
this.noteSell = noteSell;
}
public static void main(String[] args) {
System.out.println("Hello Currency!");
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getIsoCode() {
return isoCode;
}
public void setIsoCode(String isoCode) {
this.isoCode = isoCode;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getTransferPurchase() {
return transferPurchase;
}
public void setTransferPurchase(double transferPurchase) {
this.transferPurchase = transferPurchase;
}
public double getTransferSell() {
return transferSell;
}
public void setTransferSell(double transferSell) {
this.transferSell = transferSell;
}
public double getTransferChange() {
return transferChange;
}
public void setTransferChange(double transferChange) {
this.transferChange = transferChange;
}
public double getTransferLast() {
return transferLast;
}
public void setTransferLast(double transferLast) {
this.transferLast = transferLast;
}
public double getTransferDelta() {
return transferDelta;
}
public void setTransferDelta(double transferDelta) {
this.transferDelta = transferDelta;
}
public double getNotePurchase() {
return notePurchase;
}
public void setNotePurchase(double notePurchase) {
this.notePurchase = notePurchase;
}
public double getNoteSell() {
return noteSell;
}
public void setNoteSell(double noteSell) {
this.noteSell = noteSell;
}
@Override
public String toString() {
return "Currency{" +
"country='" + country + '\'' +
", isoCode='" + isoCode + '\'' +
", unit='" + unit + '\'' +
", name='" + name + '\'' +
", transferPurchase=" + transferPurchase +
", transferSell=" + transferSell +
", transferChange=" + transferChange +
", transferLast=" + transferLast +
", transferDelta=" + transferDelta +
", notePurchase=" + notePurchase +
", noteSell=" + noteSell +
'}';
}
}
OSGI-INF.blueprint.currency-ctx.xml:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<bean id="accountOne" class="com.domain.subdomain.Account" init-method="startUp">
<property name="currency" ref="currencyUS" />
</bean>
<bean id="accountTwo" class="com.domain.subdomain.Account" init-method="startUp">
<property name="currency" ref="currencyEU" />
</bean>
<bean id="currencyUS" class="com.domain.subdomain.Currency">
<argument value="USA"/> <!-- country -->
<argument value="US"/> <!-- isoCode -->
<argument value="1"/> <!-- unit -->
<argument value="Dollar"/> <!-- name -->
<argument value="7.91"/> <!-- transferPurchase -->
<argument value="7.82"/> <!-- transferSell -->
<argument value="0.83"/> <!-- transferChange -->
<argument value="7.94"/> <!-- transferLast -->
<argument value="7.95"/> <!-- transferDelta -->
<argument value="7.59"/> <!-- notePurchase -->
<argument value="8.31"/> <!-- noteSell -->
</bean>
<bean id="currencyEU" class="com.domain.subdomain.Currency">
<argument value="European Union"/> <!-- country -->
<argument value="EU"/> <!-- isoCode -->
<argument value="1"/> <!-- unit -->
<argument value="Euro"/> <!-- name -->
<argument value="9.36"/> <!-- transferPurchase -->
<argument value="9.43"/> <!-- transferSell -->
<argument value="6.14"/> <!-- transferChange -->
<argument value="9.33"/> <!-- transferLast -->
<argument value="9.39"/> <!-- transferDelta -->
<argument value="8.90"/> <!-- notePurchase -->
<argument value="9.89"/> <!-- noteSell -->
</bean>
</blueprint>
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>
<groupId>com.domain.subdomain</groupId>
<artifactId>blueprint-bank-account-example</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- Annotations -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.2</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>javax.transaction-api</artifactId>
<version>1.2</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.aries.blueprint</groupId>
<artifactId>blueprint-maven-plugin-annotation</artifactId>
<version>1.3.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.ops4j.pax.cdi</groupId>
<artifactId>pax-cdi-api</artifactId>
<version>0.8.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.spring-beans</artifactId>
<version>3.2.11.RELEASE_1</version>
<optional>true</optional>
</dependency>
<!-- //Annotations -->
<!-- SPI -->
<dependency>
<groupId>org.apache.aries.blueprint</groupId>
<artifactId>blueprint-maven-plugin-spi</artifactId>
<version>1.1.0</version>
</dependency>
<!-- //SPI -->
</dependencies>
<build>
<plugins>
<!-- BluePrint -->
<plugin>
<groupId>org.apache.aries.blueprint</groupId>
<artifactId>blueprint-maven-plugin</artifactId>
<version>1.9.0</version>
<configuration>
<scanPaths>
<scanPath>com.domain.subdomain</scanPath>
</scanPaths>
</configuration>
</plugin>
<!-- //BluePrint -->
</plugins>
</build>
</project>
OSGi 包是一种 插件,您 运行 在 OSGi 容器中(JBoss Fuse、Apache Karaf、Eclipse Equinox 等)。所以你不需要 main
方法。
当您使用 Maven 构建 OSGi 包时,指定 <packaging>bundle</packaging>
并添加
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<version>3.3.0</version>
</plugin>
因为 bundle jar 有一些额外的 headers(由这个插件添加)告诉 OSGi 容器加载蓝图文件。
您可以将 Blueprint 想象成与 Spring 非常相似的东西:您在 XML 文件中声明 bean 和依赖项。在你的例子中,你只是声明了将被实例化的 beans,但是没有 "does something".
的代码
我不知道 blueprint-maven-plugin
,但我想这 运行 是您在一个小容器中的捆绑包。你如何从 maven 调用它?
我高度怀疑运行将您的项目与 "Run Account SHIFT+F10" 结合在一起,您基本上只是 运行将此应用程序作为常规 Java 应用程序而不是 OSGi 蓝图包。
我是 OSGI-INF 蓝图的初学者。 我有两个 类 命名的帐户和货币。我现在正尝试通过在 IntelliJ 中按 "Run Account SHIFT+F10" 来启动我的程序。然后我就得到了这个:
Hello Account!
但我想让它写 Currency 方法 toString()。
账户:
package com.domain.subdomain;
public class Account {
private Currency currency;
public Account() {
}
public void setCurrency(Currency currency){
this.currency = currency;
}
public static void main(String[] args) {
System.out.println("Hello Account!");
}
}
货币:
package com.domain.subdomain;
public class Currency {
String country;
String isoCode;
String unit;
String name;
double transferPurchase;
double transferSell;
double transferChange;
double transferLast;
double transferDelta;
double notePurchase;
double noteSell;
public Currency(){
}
public Currency(String country, String isoCode, String unit, String name, double transferPurchase, double transferSell, double transferChange, double transferLast, double transferDelta, double notePurchase, double noteSell) {
this.country = country;
this.isoCode = isoCode;
this.unit = unit;
this.name = name;
this.transferPurchase = transferPurchase;
this.transferSell = transferSell;
this.transferChange = transferChange;
this.transferLast = transferLast;
this.transferDelta = transferDelta;
this.notePurchase = notePurchase;
this.noteSell = noteSell;
}
public static void main(String[] args) {
System.out.println("Hello Currency!");
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getIsoCode() {
return isoCode;
}
public void setIsoCode(String isoCode) {
this.isoCode = isoCode;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getTransferPurchase() {
return transferPurchase;
}
public void setTransferPurchase(double transferPurchase) {
this.transferPurchase = transferPurchase;
}
public double getTransferSell() {
return transferSell;
}
public void setTransferSell(double transferSell) {
this.transferSell = transferSell;
}
public double getTransferChange() {
return transferChange;
}
public void setTransferChange(double transferChange) {
this.transferChange = transferChange;
}
public double getTransferLast() {
return transferLast;
}
public void setTransferLast(double transferLast) {
this.transferLast = transferLast;
}
public double getTransferDelta() {
return transferDelta;
}
public void setTransferDelta(double transferDelta) {
this.transferDelta = transferDelta;
}
public double getNotePurchase() {
return notePurchase;
}
public void setNotePurchase(double notePurchase) {
this.notePurchase = notePurchase;
}
public double getNoteSell() {
return noteSell;
}
public void setNoteSell(double noteSell) {
this.noteSell = noteSell;
}
@Override
public String toString() {
return "Currency{" +
"country='" + country + '\'' +
", isoCode='" + isoCode + '\'' +
", unit='" + unit + '\'' +
", name='" + name + '\'' +
", transferPurchase=" + transferPurchase +
", transferSell=" + transferSell +
", transferChange=" + transferChange +
", transferLast=" + transferLast +
", transferDelta=" + transferDelta +
", notePurchase=" + notePurchase +
", noteSell=" + noteSell +
'}';
}
}
OSGI-INF.blueprint.currency-ctx.xml:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<bean id="accountOne" class="com.domain.subdomain.Account" init-method="startUp">
<property name="currency" ref="currencyUS" />
</bean>
<bean id="accountTwo" class="com.domain.subdomain.Account" init-method="startUp">
<property name="currency" ref="currencyEU" />
</bean>
<bean id="currencyUS" class="com.domain.subdomain.Currency">
<argument value="USA"/> <!-- country -->
<argument value="US"/> <!-- isoCode -->
<argument value="1"/> <!-- unit -->
<argument value="Dollar"/> <!-- name -->
<argument value="7.91"/> <!-- transferPurchase -->
<argument value="7.82"/> <!-- transferSell -->
<argument value="0.83"/> <!-- transferChange -->
<argument value="7.94"/> <!-- transferLast -->
<argument value="7.95"/> <!-- transferDelta -->
<argument value="7.59"/> <!-- notePurchase -->
<argument value="8.31"/> <!-- noteSell -->
</bean>
<bean id="currencyEU" class="com.domain.subdomain.Currency">
<argument value="European Union"/> <!-- country -->
<argument value="EU"/> <!-- isoCode -->
<argument value="1"/> <!-- unit -->
<argument value="Euro"/> <!-- name -->
<argument value="9.36"/> <!-- transferPurchase -->
<argument value="9.43"/> <!-- transferSell -->
<argument value="6.14"/> <!-- transferChange -->
<argument value="9.33"/> <!-- transferLast -->
<argument value="9.39"/> <!-- transferDelta -->
<argument value="8.90"/> <!-- notePurchase -->
<argument value="9.89"/> <!-- noteSell -->
</bean>
</blueprint>
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>
<groupId>com.domain.subdomain</groupId>
<artifactId>blueprint-bank-account-example</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- Annotations -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.2</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>javax.transaction-api</artifactId>
<version>1.2</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.aries.blueprint</groupId>
<artifactId>blueprint-maven-plugin-annotation</artifactId>
<version>1.3.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.ops4j.pax.cdi</groupId>
<artifactId>pax-cdi-api</artifactId>
<version>0.8.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.spring-beans</artifactId>
<version>3.2.11.RELEASE_1</version>
<optional>true</optional>
</dependency>
<!-- //Annotations -->
<!-- SPI -->
<dependency>
<groupId>org.apache.aries.blueprint</groupId>
<artifactId>blueprint-maven-plugin-spi</artifactId>
<version>1.1.0</version>
</dependency>
<!-- //SPI -->
</dependencies>
<build>
<plugins>
<!-- BluePrint -->
<plugin>
<groupId>org.apache.aries.blueprint</groupId>
<artifactId>blueprint-maven-plugin</artifactId>
<version>1.9.0</version>
<configuration>
<scanPaths>
<scanPath>com.domain.subdomain</scanPath>
</scanPaths>
</configuration>
</plugin>
<!-- //BluePrint -->
</plugins>
</build>
</project>
OSGi 包是一种 插件,您 运行 在 OSGi 容器中(JBoss Fuse、Apache Karaf、Eclipse Equinox 等)。所以你不需要 main
方法。
当您使用 Maven 构建 OSGi 包时,指定 <packaging>bundle</packaging>
并添加
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<version>3.3.0</version>
</plugin>
因为 bundle jar 有一些额外的 headers(由这个插件添加)告诉 OSGi 容器加载蓝图文件。
您可以将 Blueprint 想象成与 Spring 非常相似的东西:您在 XML 文件中声明 bean 和依赖项。在你的例子中,你只是声明了将被实例化的 beans,但是没有 "does something".
的代码我不知道 blueprint-maven-plugin
,但我想这 运行 是您在一个小容器中的捆绑包。你如何从 maven 调用它?
我高度怀疑运行将您的项目与 "Run Account SHIFT+F10" 结合在一起,您基本上只是 运行将此应用程序作为常规 Java 应用程序而不是 OSGi 蓝图包。