java - org.osgi.framework.BundleException : Unable to resolve: missing requirement: osgi. wiring.package; (osgi.wiring.package=org.json)

标签 java maven osgi apache-karaf apache-felix

我是 Java/Karaf 4.0.9/Maven/Pom/Camel 的新手,我无法解决问题

pom.xml文件中的Json部分,这里我改了很多Json version , 但没有用。

            <dependency>
                <groupId>org.json</groupId>
                <artifactId>json</artifactId>
                <version>20151123</version>
            </dependency>

我在这里附上了我的 Pom.xml 文件,我用谷歌搜索了它。并得到 same issue in GSON但我不知道如何解决 felix 中的问题。

        <?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/maven-v4_0_0.xsd">

            <modelVersion>4.0.0</modelVersion>

            <groupId>PaxelESBNotification</groupId>
            <artifactId>PaxelESBNotification</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <packaging>jar</packaging>

            <name>A Camel Blueprint Route</name>

            <properties>
                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            </properties>

            <dependencyManagement>
                <dependencies>
                    <!-- Camel BOM -->
                    <dependency>
                        <groupId>org.apache.camel</groupId>
                        <artifactId>camel-parent</artifactId>
                        <version>2.16.5</version>
                        <scope>import</scope>
                        <type>pom</type>
                    </dependency>
                </dependencies>
            </dependencyManagement>

            <dependencies>
                <!-- Camel -->
                <dependency>
                    <groupId>org.apache.camel</groupId>
                    <artifactId>camel-core</artifactId>
                </dependency>
                <dependency>
                    <groupId>org.apache.camel</groupId>
                    <artifactId>camel-rabbitmq</artifactId>
                </dependency>
                <dependency>
                    <groupId>org.json</groupId>
                    <artifactId>json</artifactId>
                    <version>20151123</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.camel</groupId>
                    <artifactId>camel-mail</artifactId>
                </dependency>
                <dependency>
                    <groupId>org.apache.camel</groupId>
                    <artifactId>camel-stream</artifactId>
                </dependency>

                <!-- Testing -->
                <dependency>
                    <groupId>org.apache.camel</groupId>
                    <artifactId>camel-test-blueprint</artifactId>
                    <scope>test</scope>
                </dependency>

                <!-- logging -->
                <dependency>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-api</artifactId>
                    <version>2.7</version>
                </dependency>
                <!-- <dependency>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-core</artifactId>
                    <version>2.7</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-slf4j-impl</artifactId>
                    <version>2.7</version>
                </dependency> -->
            </dependencies>

            <build>
                <plugins>
                <!-- compiler plugin -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.7.0</version>
                        <configuration>
                            <source>1.8</source>
                            <target>1.8</target>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-resources-plugin</artifactId>
                        <version>3.0.2</version>
                        <configuration>
                            <encoding>UTF-8</encoding>
                        </configuration>
                    </plugin>

                    <!-- to generate the MANIFEST.MF of the bundle -->
                    <plugin>
                        <groupId>org.apache.felix</groupId>
                        <artifactId>maven-bundle-plugin</artifactId>
                        <version>3.5.0</version>
                        <extensions>false</extensions>
                        <executions>
                            <execution>
                                <id>bundle-manifest</id>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>manifest</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- to include MANIFEST.MF in the 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>

                    <!-- to run the example using mvn camel:run -->
                    <plugin>
                        <groupId>org.apache.camel</groupId>
                        <artifactId>camel-maven-plugin</artifactId>
                        <version>2.16.5</version>
                        <!-- <version>3.3.3</version> -->
                    </plugin>
                </plugins>
            </build>

        </project>

java文件

    import org.apache.camel.Exchange;
    import org.apache.camel.Processor;
    import org.json.JSONObject;

    public class EmailProcessor implements Processor {
        public void process(Exchange exchange) throws Exception {
            String RequestPayload = exchange.getIn().getBody(String.class);
            JSONObject obj = new JSONObject(RequestPayload);
            String mail_id_to = obj.get("email").toString();
            String mail_subject = obj.get("subject").toString();
            String mail_content = obj.get("content").toString();

            System.out.print(mail_id_to);
            System.out.print(mail_subject);
            System.out.print(mail_content);
        }
    }

错误

    ERROR: Bundle PaxelESBNotification [226] Error starting file:/home/ubuntu/Software/service_mix/apache-servicemix-7.0.1/deploy/PaxelESBNotification-0.0.1-SNAPSHOT.jar (org.osgi.framework.BundleException: Unable to resolve PaxelESBNotification [226](R 226.0): missing requirement [PaxelESBNotification [226](R 226.0)] osgi.wiring.package; (osgi.wiring.package=org.json) Unresolved requirements: [[PaxelESBNotification [226](R 226.0)] osgi.wiring.package; (osgi.wiring.package=org.json)])
    org.osgi.framework.BundleException: Unable to resolve PaxelESBNotification [226](R 226.0): missing requirement [PaxelESBNotification [226](R 226.0)] osgi.wiring.package; (osgi.wiring.package=org.json) Unresolved requirements: [[PaxelESBNotification [226](R 226.0)] osgi.wiring.package; (osgi.wiring.package=org.json)]
        at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4132)
        at org.apache.felix.framework.Felix.startBundle(Felix.java:2117)
        at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1371)
        at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:308)
        at java.lang.Thread.run(Thread.java:748)

我该如何解决这个问题?

最佳答案

您的构建看起来很棒。据我所知,您生成了一个有效的 bundle 。

现在在运行时你必须提供你的项目依赖的所有包。错误消息告诉您您的包需要一个包 org.json。所以你需要安装一个 bunde 来导出这个包。

你可以试试这个包:

 install -s mvn:org.json/json/20180813

您还应该考虑在构建期间创建一个功能文件,允许一次性安装您的代码,包括依赖项。

关于java - org.osgi.framework.BundleException : Unable to resolve: missing requirement: osgi. wiring.package; (osgi.wiring.package=org.json),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55862916/

相关文章:

java - 后增量,前增量。 JAVA

java - Arrays.sort(Object[] a) - 它是如何实现的?

java - 如何重定向到servlet中的错误页面?

java - Android通过http读取xml

java - OSGi JAR 一旦运行,是否可以要求其容器从另一个位置加载另一个 OSGi JAR?

scala - 在 OSGi 中创建 Akka 项目

eclipse - 如何在eclipse中全局添加jboss存储库到maven?

eclipse - M2E:版本与父版本重复 - 为什么这是一个警告?

java - Maven 阴影插件删除 "original"

java - 如何使用 OSGi 片段包注册自定义 Logback 过滤器?