Java 未生成OSGI-INF文件夹

Java 未生成OSGI-INF文件夹,java,maven-2,apache-felix,osgi-bundle,Java,Maven 2,Apache Felix,Osgi Bundle,我是OSGI新手,在生成的jar文件中获取OSGI-INF文件夹时遇到了麻烦。 我需要有如下文件夹结构 META-INF OSGI-INF Com.mine.cq 我正在使用Eclipse和m2e插件。当我运行我的项目时,我获得了构建成功。我在生成的jar文件中得到下面的文件夹结构 META-INF Com.mine.cq 这是我的POM.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http:

我是OSGI新手,在生成的jar文件中获取OSGI-INF文件夹时遇到了麻烦。 我需要有如下文件夹结构

  • META-INF
  • OSGI-INF
  • Com.mine.cq
我正在使用Eclipse和m2e插件。当我运行我的项目时,我获得了构建成功。我在生成的jar文件中得到下面的文件夹结构

  • META-INF
  • Com.mine.cq
这是我的POM.xml

 <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.mine.cq</groupId>
  <artifactId>mineCore</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>mineCore</name>
  <url>http://maven.apache.org</url>

  <properties>
        <file.encoding>utf-8</file.encoding>
    </properties>
   <build>
        <defaultGoal>install</defaultGoal>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>1.0-alpha-3</version>
                <executions>
                    <execution>
                        <id>enforce-java</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <requireMavenVersion>
                                    <message>Project must be built with Maven 2.0.7 or higher</message>
                                    <version>2.0.7</version>
                                </requireMavenVersion>
                                <requireJavaVersion>
                                    <message>Project must be compiled with Java 5 or higher</message>
                                    <version>1.5.0</version>
                                </requireJavaVersion>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>1.4.3</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Export-Package>
                            com.mine.cq.mineCore.*
                        </Export-Package>
                        <Import-Package>
                            *;resolution:=optional,
                            javax.servlet;version=2.4,
                            javax.servlet.http;version=2.4
                        </Import-Package>
                        <Embed-Dependency>   
                        </Embed-Dependency>
                        <Embed-Transitive>true</Embed-Transitive>
                        <Include-Resource>{maven-resources}</Include-Resource>
                        <Sling-Bundle-Resources>/var/classes</Sling-Bundle-Resources>
                    </instructions>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-scm-plugin</artifactId>
                <version>1.0</version>
                <configuration>
                    <goals>install</goals>
                </configuration>
            </plugin>
        </plugins>
    </build>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

4.0.0
com.mine.cq
地雷芯
0.0.1-快照
罐子
地雷芯
http://maven.apache.org
utf-8
安装
org.apache.maven.plugins
maven enforcer插件
1.0-α-3
强制执行java
执行
项目必须使用Maven 2.0.7或更高版本构建
2.0.7
项目必须使用Java 5或更高版本编译
1.5.0
org.apache.felix
maven捆绑插件
1.4.3
真的
com.mine.cq.mineCore*
*;分辨率:=可选,
javax.servlet;版本=2.4,
javax.servlet.http;版本=2.4
真的
{maven资源}
/风险值/类别
org.apache.maven.plugins
maven scm插件
1
安装
朱尼特
朱尼特
3.8.1
测试
为什么OSGI-INF文件夹不在.jar文件中?我需要在OSGO-INF文件夹中设置一些信息,因为我必须将我的组件注册为OSGI服务。
请指导我完成它。

您的pom.xml需要具有“bundle”而不是“jar”的打包类型。如果希望包装类型为“jar”,请使用以下命令:

编辑:哦!这是唯一的问题之一。另一个问题是,我认为你无法生成 带有maven bundle插件的OSGI-INF。您需要自己在src/main/resources中创建OSGI-INF文件夹,或者使用生成OSGI-INF的插件


maven scr插件可以生成OSGI-INF,但它只有在使用scr时才有用

您的pom.xml需要具有“bundle”而不是“jar”的打包类型。如果希望包装类型为“jar”,请使用以下命令:

编辑:哦!这是唯一的问题之一。另一个问题是,我认为你无法生成 带有maven bundle插件的OSGI-INF。您需要自己在src/main/resources中创建OSGI-INF文件夹,或者使用生成OSGI-INF的插件


maven scr插件可以生成OSGI-INF,但它只有在使用scr时才有用

虽然已经很晚了,但我会就这个问题发表我的意见,以供将来参考

如前所述,如果遵循中给出的说明,可以将捆绑包的“打包”设置为“jar”

这里有一个小问题:使用该配置,您需要在插件配置中显式添加
true
,以便正确创建SCR xml文件(还记得调整清单位置,因为在文档中没有该部分!)

您可以在这里看到一个示例(与您的示例完全不同,但如果您仍然感兴趣,我假设您可以在代码中轻松地减少它):


4.0.0
com.massimobono.karaf.examples
用户示例
0.0.1-快照
罐子
org.apache.maven.plugins
maven jar插件
3.0.2
${project.build.outputDirectory}/META-INF/MANIFEST.MF
org.apache.felix
maven捆绑插件
3.2.0
真的
捆绑清单
进程类
显示
${project.build.outputDirectory}/META-INF/
真的
罐子
捆
战争
${project.groupId}.${project.artifactId}
*
1.8
1.8
UTF-8
org.osgi
org.osgi.core
6.0.0
假如
org.osgi
org.osgi.service.component.annotations
1.3.0

虽然我已经很晚了,但我会就这个问题发表我的意见,以供将来参考

如前所述,如果遵循中给出的说明,可以将捆绑包的“打包”设置为“jar”

只是有一点小把戏:和t
<?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.massimobono.karaf.examples</groupId>
    <artifactId>user-example</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <packaging>jar</packaging>    
    <build>
        <plugins>
            <plugin>
                <!-- Here you specifiy that you want to use the manifest file generated by maven bundle plugin -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.0.2</version>
                <configuration>
                    <archive>
                        <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                    </archive>
                </configuration>
            </plugin>
            <!-- Here you generate the whole MANIFEST by using maven-bundle-plugin -->
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>3.2.0</version>
                <extensions>true</extensions> <!-- make sure this is present -->
                <executions>
                    <execution>
                        <id>bundle-manifest</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>manifest</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <manifestLocation>${project.build.outputDirectory}/META-INF/</manifestLocation> <!-- make sure this is present! in the example of maven bundle plugin documentation, this piece is NOT present -->
                    <exportScr>true</exportScr> <!-- be sure to add this line as well -->
                    <supportedProjectTypes>
                        <supportedProjectType>jar</supportedProjectType>
                        <supportedProjectType>bundle</supportedProjectType>
                        <supportedProjectType>war</supportedProjectType>
                    </supportedProjectTypes>
                    <instructions>
                        <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
                        <_dsannotations>*</_dsannotations>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.core</artifactId>
            <version>6.0.0</version>
            <scope>provided</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.osgi/org.osgi.service.component.annotations -->
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.service.component.annotations</artifactId>
            <version>1.3.0</version>
        </dependency>


    </dependencies>

</project>