【问题标题】:OSGi and Virgo tools : impossible to add a maven project (using bnd maven plugin)OSGi 和 Virgo 工具:无法添加 maven 项目(使用 bnd maven 插件)
【发布时间】:2012-10-16 02:37:02
【问题描述】:

我是 OSGi 新手,只编写了几个包并手动部署它们。 我的一些朋友向我介绍了 Virgo 和 Virgo 工具,它们允许您自动部署使用 eclipse 管理的包。

我目前正在尝试设置所有这些。我有 virgo-tomcat-server-3.5.0.RELEASE,以及 virgo 工具 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 文件。

我终于解决了我面临的问题。

  1. 由于我将我的包作为 maven 项目导入 STS,因此我必须将 Virgo 方面添加到其中。一旦我更新了我的 maven 配置,它就会搞砸我的项目,我会收到以下错误:

    Java compiler level does not match the version of the installed Java project facet.
    
  2. Appart from my (shitty) maven configuration,我发现自己无法将我的项目添加到 virgo 服务器中,这无休止地告诉我

    null reason : null
    

有人知道吗?

【问题讨论】:

  • 刚刚用我的命令行启动了“mvn clean install”,发现“Manifest-Version”是1.0。这很糟糕,因为 Virgo 带有 R4 OSGi 的实现,它只接受 V2.0 版本的清单文件。继续搜索。

标签: osgi m2eclipse facet eclipse-virgo bnd


【解决方案1】:

万岁!问题解决了。

首先:关于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 bundle项目添加到virgo。

  1. 正确配置 bnd,通过在正确的 maven 阶段运行它的“清单”目标(例如:在你的类被编译之后),并告诉他在哪里可以找到清单。这解决了“null 原因:null”问题(也许 virgo 应该说:“could not find 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>
    

  2. 将此目标添加到 m2eclipse 生命周期映射中。这会在每次出现您在 bnd 配置中指定的阶段后刷新您的清单(此处为:流程类阶段)。否则,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>
    

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2014-07-04
    • 1970-01-01
    • 2012-09-26
    • 2010-10-11
    • 2020-03-02
    • 2012-01-20
    • 1970-01-01
    • 2010-11-19
    • 1970-01-01
    相关资源
    最近更新 更多