我是 OSGi 新手,只编写了几个包并手动部署它们。 我的一些 friend 告诉我 Virgo 和 Virgo 工具,它们允许您自动部署使用 eclipse 管理的包。
我目前正在尝试设置这一切。我有 virgo-tomcat-server-3.5.0.RELEASE 以及 virgo tools 1.0.0,所有这些都安装在 Spring Tool Suite 3.1.0.RELEASE 上(如果您不知道,最后一个包括m2eclipse 插件)。
我的包是一个 Maven 项目。它使用 bnd 插件,这是它的配置
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>fr.tpepio.mtg.model</Export-Package>
</instructions>
</configuration>
<executions>
<execution>
<id>build-manifest</id>
<phase>compile</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
你可以看到我只导出了一个包。我还尝试让 m2eclipse 在 eclipse 编译我的类时动态生成我的manifest.mf 文件。
我终于解决了我面临的问题。
由于我将 bundle 作为 Maven 项目导入到 STS 中,因此我必须向其中添加 Virgo 方面。一旦我更新了我的 Maven 配置,它就会搞乱我的项目,并且出现以下错误:
Java compiler level does not match the version of the installed Java project facet.
除了我的(糟糕的)maven 配置之外,我发现自己无法将我的项目添加到 virgo 服务器中,这不断地告诉我
null reason : null
有人有任何线索吗?
最佳答案
万岁!问题已解决。
首先:关于java编译器和facet的java版本。告诉 maven 你的源代码是用 1.6 编码的,并且必须用 1.6 编译将解决这个问题。代码如下:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<inherited>true</inherited>
<configuration>
<verbose>false</verbose>
<encoding>${java.compiler.encoding}</encoding>
<fork>true</fork>
<source>${java.compile.version}</source>
<target>${java.compile.version}</target>
</configuration>
我仍然不明白为什么它解决了这个问题,因为我的项目配置和STS配置都只能使用java 6...我相信这是因为我的源代码编译为1.5 java源代码。
第二:将 Maven 捆绑项目添加到 virgo。
通过在正确的 maven 阶段运行其“ list ”目标来正确配置 bnd(例如:在编译您的类之后),并告诉他在哪里可以找到 list 。这解决了“空原因:空”问题(也许处女座应该说:“找不到manifest.mf...?)。
<plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <version>2.3.7</version> <extensions>true</extensions> <configuration> <instructions> <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName> <Bundle-Name>${project.name}</Bundle-Name> <Bundle-Version>${project.version}</Bundle-Version> <Bundle-ClassPath>.</Bundle-ClassPath> <Export-Package> [packages you want to export] </Export-Package> </instructions> </configuration> <executions> <execution> <id>bundle-manifest</id> <phase>process-classes</phase> <goals> <goal>manifest</goal> </goals> <configuration> <manifestLocation>src/main/resources/META-INF/</manifestLocation> </configuration> </execution> </executions>
将此目标添加到 m2eclipse 生命周期映射中。每次出现您在 bnd 配置中指定的阶段(此处:进程类阶段)后,这都会刷新您的 list 。否则,m2eclipse 无法了解何时应该调用您的目标。
<pluginManagement> <plugins> <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.--> <plugin> <groupId>org.eclipse.m2e</groupId> <artifactId>lifecycle-mapping</artifactId> <version>1.0.0</version> <configuration> <lifecycleMappingMetadata> <pluginExecutions> <!-- Maven Bundle Plugin --> <pluginExecution> <pluginExecutionFilter> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <versionRange>[2.3.7,)</versionRange> <goals> <goal>manifest</goal> </goals> </pluginExecutionFilter> <action> <execute> <runOnIncremental>false</runOnIncremental> </execute> </action> </pluginExecution> </pluginExecutions> </lifecycleMappingMetadata> </configuration> </plugin> </plugins>
希望这会有所帮助。
关于OSGi 和 Virgo 工具 : impossible to add a maven project (using bnd maven plugin),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13076591/