如何将org.json(json)添加到我的应用程序中,以便它成功部署到JBoss Fuse?

时间:2017-09-29 16:11:12

标签: java-8 apache-camel jbossfuse

背景:

我想使用org.json.JSONArray和org.json.JSONObject,但我不清楚如何在JBoss Fuse容器中添加支持。

问题:

简单地将jar(即“json-20170516.jar”)放入JBoss Fuse“deploy”文件夹中不会出现就足够了。
- 事实上,它似乎会引起其他捆绑包的问题......

即,

    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20170516</version>
        <type>jar</type>
    </dependency>

问题

是否有可能在JBoss Fuse中为这个API提供支持 - 如果是的话,如何实现这一点?

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>aaa.bbb.ccc</groupId>
    <artifactId>myTestProj</artifactId>
    <version>1</version>
    <packaging>bundle</packaging>
    <name>myTestProj</name>
    <description>myTestProj</description>

    <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <skipTests>true</skipTests>
    <mq.version>8.0.0.7</mq.version>
    </properties>

    <dependencies>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.25</version>
        <scope>provided</scope>               
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.25</version>
        <scope>provided</scope>               
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-core</artifactId>
        <version>2.17.0</version>
        <scope>provided</scope>
    </dependency>           
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-restlet</artifactId>
        <version>2.17.0</version> 
        <scope>provided</scope>                     
    </dependency> 
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-cdi</artifactId>
        <version>2.17.0</version> 
        <scope>provided</scope>                     
    </dependency>   

    <!-- testing "netty4-http" -->     
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-netty4-http</artifactId>
        <version>2.17.0</version> 
        <scope>provided</scope>                     
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-jackson</artifactId>
        <version>2.17.0</version>
        <scope>provided</scope>               
    </dependency>          
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-http4</artifactId>
        <version>2.17.0</version>
        <scope>provided</scope>
    </dependency>                        
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-cxf</artifactId>
        <version>2.17.0</version>
        <scope>provided</scope>              
    </dependency> 
    <dependency>
        <groupId>com.ibm.mq</groupId>
        <artifactId>allclient</artifactId>
        <version>${mq.version}</version>
        <scope>provided</scope>               
    </dependency>
    <dependency>
        <groupId>com.ibm.mq</groupId>
        <artifactId>jms</artifactId>
        <version>${mq.version}</version>
        <scope>provided</scope>
    </dependency>  
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-jsonpath</artifactId>
        <version>2.17.0</version>
        <scope>provided</scope>
    </dependency>

    <!-- version to use, as per: https://mvnrepository.com/artifact/org.apache.camel/camel-jackson/2.17.0.redhat-630283  -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.6.3</version>
    </dependency>


    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20170516</version>
        <type>jar</type>
    </dependency>

    </dependencies>

    <build>
    <finalName>${project.artifactId}-${project.version}</finalName>

    <resources>
        <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
        </resource>
    </resources>

    <plugins>

        <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
            <showDeprecation>true</showDeprecation>
        </configuration>
        </plugin> 

        <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jaxb2-maven-plugin</artifactId>
        <version>2.3</version>
        <executions>
            <execution>
            <id>xjc</id>
            <goals>
                <goal>xjc</goal>
            </goals>
            </execution>
        </executions>        
        <configuration>
            <sources>
            <source>src/main/resources/xsd/my.xsd</source>
            </sources>
            <packageName>aaa.bbb.ccc.generated</packageName>                    
            <verbose default-value="false">${xjc.verbose}</verbose>
        </configuration>                
        </plugin>              

        <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <version>3.3.0</version>
        <extensions>true</extensions>
        <configuration>
            <instructions>
            <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
            <Export-Package>aaa.bbb.ccc*</Export-Package> 
            <Import-Package>*</Import-Package>                                                                      
            </instructions>
        </configuration>
        </plugin>             
    </plugins>
    </build>
</project>

部署文件夹看起来像这样......     C:\工具\ JBoss的熔丝-6.3.0.redhat-187 \部署&GT; DIR      驱动器C中的卷是OSDisk      卷序列号为D89B-75DE

 Directory of C:\tools\jboss-fuse-6.3.0.redhat-187\deploy

09/29/2017  11:58 AM    <DIR>          .
09/29/2017  11:58 AM    <DIR>          ..
09/29/2017  11:37 AM            20,073 myTestProj-1.jar
06/29/2017  01:00 AM           159,649 com.ibm.mq.osgi.allclientprereqs_8.0.0.7.jar
06/29/2017  01:00 AM         8,011,749 com.ibm.mq.osgi.allclient_8.0.0.7.jar
06/29/2017  01:00 AM         4,088,715 com.ibm.mq.osgi.java_8.0.0.7.jar
06/29/2017  01:00 AM           171,064 com.ibm.msg.client.osgi.commonservices.j2se_8.0.0.7.jar
06/29/2017  01:00 AM            48,715 com.ibm.msg.client.osgi.jms.prereq_8.0.0.7.jar.DISABLE
06/29/2017  01:00 AM           639,807 com.ibm.msg.client.osgi.jms_8.0.0.7.jar
06/29/2017  01:00 AM           216,218 com.ibm.msg.client.osgi.nls_8.0.0.7.jar
06/29/2017  01:00 AM           279,861 com.ibm.msg.client.osgi.wmq.nls_8.0.0.7.jar
06/29/2017  01:00 AM            92,406 com.ibm.msg.client.osgi.wmq.prereq_8.0.0.7.jar
06/29/2017  01:00 AM         7,963,226 com.ibm.msg.client.osgi.wmq_8.0.0.7.jar
09/28/2017  12:11 PM            57,264 json-20170516.jar
09/15/2016  04:19 AM               873 README
          14 File(s)     21,771,379 bytes
           2 Dir(s)  135,870,164,992 bytes free

C:\tools\jboss-fuse-6.3.0.redhat-187\deploy>
控制台中的

记录错误如下所示(即将org.json jar添加到deploy文件夹后)

2017-09-29 11:58:11,662 | INFO  | edhat-187/deploy | BlueprintCamelContext            | 232 - org.apache.camel.camel-core - 2.17.0.redhat-630187 | Apache Camel 2.17.0.redhat-630187 (CamelContext: aaa.bbb.ccc.trans.routing) is shutting down
2017-09-29 11:58:11,663 | INFO  | edhat-187/deploy | BlueprintCamelContext            | 232 - org.apache.camel.camel-core - 2.17.0.redhat-630187 | Apache Camel 2.17.0.redhat-630187 (CamelContext: aaa.bbb.ccc.trans.routing) uptime
2017-09-29 11:58:11,663 | INFO  | edhat-187/deploy | BlueprintCamelContext            | 232 - org.apache.camel.camel-core - 2.17.0.redhat-630187 | Apache Camel 2.17.0.redhat-630187 (CamelContext: aaa.bbb.ccc.trans.routing) is shutdown in 0.001 seconds
2017-09-29 11:58:11,664 | ERROR | edhat-187/deploy | BlueprintContainerImpl           | 23 - org.apache.aries.blueprint.core - 1.4.5 | Unable to start blueprint container for bundle aaa.bbb.ccc.myTestProj/1.0.0
org.osgi.service.blueprint.container.ComponentDefinitionException: Error when instantiating bean wmqcf of class com.ibm.mq.jms.MQConnectionFactory
    at org.apache.aries.blueprint.container.BeanRecipe.wrapAsCompDefEx(BeanRecipe.java:361)[23:org.apache.aries.blueprint.core:1.4.5]
    at org.apache.aries.blueprint.container.BeanRecipe.getInstanceFromType(BeanRecipe.java:351)[23:org.apache.aries.blueprint.core:1.4.5]
    at org.apache.aries.blueprint.container.BeanRecipe.getInstance(BeanRecipe.java:282)[23:org.apache.aries.blueprint.core:1.4.5]
    at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:830)[23:org.apache.aries.blueprint.core:1.4.5]
    at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:811)[23:org.apache.aries.blueprint.core:1.4.5]
    at org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79)[23:org.apache.aries.blueprint.core:1.4.5]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_141]
    at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88)[23:org.apache.aries.blueprint.core:1.4.5]
    at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:247)[23:org.apache.aries.blueprint.core:1.4.5]
    at org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:183)[23:org.apache.aries.blueprint.core:1.4.5]
    at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:688)[23:org.apache.aries.blueprint.core:1.4.5]
    at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:383)[23:org.apache.aries.blueprint.core:1.4.5]
    at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:270)[23:org.apache.aries.blueprint.core:1.4.5]
    at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:294)[23:org.apache.aries.blueprint.core:1.4.5]
    at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:263)[23:org.apache.aries.blueprint.core:1.4.5]
    at org.apache.aries.blueprint.container.BlueprintExtender.modifiedBundle(BlueprintExtender.java:253)[23:org.apache.aries.blueprint.core:1.4.5]
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:500)[17:org.apache.aries.util:1.1.0]
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:433)[17:org.apache.aries.util:1.1.0]
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$AbstractTracked.track(BundleHookBundleTracker.java:725)[17:org.apache.aries.util:1.1.0]
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.bundleChanged(BundleHookBundleTracker.java:463)[17:org.apache.aries.util:1.1.0]
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$BundleEventHook.event(BundleHookBundleTracker.java:422)[17:org.apache.aries.util:1.1.0]
    at org.apache.felix.framework.util.SecureAction.invokeBundleEventHook(SecureAction.java:1127)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.util.EventDispatcher.createWhitelistFromHooks(EventDispatcher.java:696)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:484)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4429)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.Felix.startBundle(Felix.java:2100)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:976)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1245)[9:org.apache.felix.fileinstall:3.5.0]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1217)[9:org.apache.felix.fileinstall:3.5.0]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:1207)[9:org.apache.felix.fileinstall:3.5.0]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:504)[9:org.apache.felix.fileinstall:3.5.0]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:358)[9:org.apache.felix.fileinstall:3.5.0]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:310)[9:org.apache.felix.fileinstall:3.5.0]
Caused by: java.lang.NoClassDefFoundError: com/ibm/msg/client/commonservices/j2se/CommonServicesImplementation
    at com.ibm.msg.client.commonservices.j2se.J2SEComponent.getFactoryClass(J2SEComponent.java:121)[com.ibm.mq.jmqi.jar:8.0.0.7 - p800-007-170629]
    at com.ibm.msg.client.commonservices.componentmanager.Component.getDetails(Component.java:250)[com.ibm.mq.jmqi.jar:8.0.0.7 - p800-007-170629]
    at com.ibm.msg.client.commonservices.trace.Trace.getVersion(Trace.java:2108)[com.ibm.mq.jmqi.jar:8.0.0.7 - p800-007-170629]
    at com.ibm.msg.client.commonservices.trace.Trace.createFFSTString(Trace.java:2053)[com.ibm.mq.jmqi.jar:8.0.0.7 - p800-007-170629]
    at com.ibm.msg.client.commonservices.trace.Trace.ffstInternal(Trace.java:1938)[com.ibm.mq.jmqi.jar:8.0.0.7 - p800-007-170629]
    at com.ibm.msg.client.commonservices.trace.Trace.ffst(Trace.java:1795)[com.ibm.mq.jmqi.jar:8.0.0.7 - p800-007-170629]
    at com.ibm.msg.client.jms.JmsFactoryFactory.getInstance(JmsFactoryFactory.java:205)[com.ibm.mqjms.jar:8.0.0.7 - p800-007-170629]
    at com.ibm.mq.jms.MQConnectionFactory.initialiseMQConnectionFactory(MQConnectionFactory.java:3210)[com.ibm.mqjms.jar:8.0.0.7 - p800-007-170629]
    at com.ibm.mq.jms.MQConnectionFactory.<init>(MQConnectionFactory.java:252)[com.ibm.mqjms.jar:8.0.0.7 - p800-007-170629]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)[:1.8.0_141]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)[:1.8.0_141]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)[:1.8.0_141]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)[:1.8.0_141]
    at org.apache.aries.blueprint.utils.ReflectionUtils.newInstance(ReflectionUtils.java:331)
    at org.apache.aries.blueprint.container.BeanRecipe.newInstance(BeanRecipe.java:984)
    at org.apache.aries.blueprint.container.BeanRecipe.getInstanceFromType(BeanRecipe.java:349)
    ... 31 more
Caused by: java.lang.ClassNotFoundException: Unable to load class 'com.ibm.msg.client.commonservices.j2se.CommonServicesImplementation' because the bundle wiring for com.ibm.msg.client.osgi.commonservices.j2se is no longer valid.
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1521)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:77)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1993)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)[:1.8.0_141]
    ... 47 more
2017-09-29 11:58:11,667 | INFO  | AMQ-1-thread-1   | MessageDatabase                  | 219 - org.apache.activemq.activemq-osgi - 5.11.0.redhat-630187 | Recovering from the journal @2:16034966
2017-09-29 11:58:11,675 | INFO  | edhat-187/deploy | fileinstall                      | 9 - org.apache.felix.fileinstall - 3.5.0 | Started bundle: file:/C:/tools/jboss-fuse-6.3.0.redhat-187/deploy/myTestProj-1.jar
2017-09-29 11:58:11,676 | INFO  | edhat-187/deploy | fileinstall                      | 9 - org.apache.felix.fileinstall - 3.5.0 | Started bundle: file:/C:/tools/jboss-fuse-6.3.0.redhat-187/deploy/myTestProj-1.jar
2017-09-29 11:58:11,680 | INFO  | edhat-187/deploy | fileinstall                      | 9 - org.apache.felix.fileinstall - 3.5.0 | Started bundle: file:/C:/tools/jboss-fuse-6.3.0.redhat-187/deploy/json-20170516.jar
2017-09-29 11:58:11,689 | INFO  | AMQ-1-thread-1   | MessageDatabase                  | 219 - org.apache.activemq.activemq-osgi - 5.11.0.redhat-630187 | Recovery replayed 235 operations from the journal in 0.048 seconds.
2017-09-29 11:58:11,699 | INFO  | AMQ-1-thread-1   | PListStoreImpl                   | 219 - org.apache.activemq.activemq-osgi - 5.11.0.redhat-630187 | PListStore:[C:\tools\jboss-fuse-6.3.0.redhat-187\data\amq\amq\tmp_storage] started
2017-09-29 11:58:11,848 | INFO  | AMQ-1-thread-1   | BrokerService                    | 219 - org.apache.activemq.activemq-osgi - 5.11.0.redhat-630187 | Apache ActiveMQ 5.11.0.redhat-630187 (amq, ID:AAXA22A747-54051-1506700691718-0:1) is starting
2017-09-29 11:58:11,933 | INFO  | AMQ-1-thread-1   | TransportServerThreadSupport     | 219 - org.apache.activemq.activemq-osgi - 5.11.0.redhat-630187 | Listening for connections at: tcp://127.0.0.1:61616
2017-09-29 11:58:11,934 | INFO  | AMQ-1-thread-1   | TransportConnector               | 219 - org.apache.activemq.activemq-osgi - 5.11.0.redhat-630187 | Connector openwire started
2017-09-29 11:58:11,934 | INFO  | AMQ-1-thread-1   | BrokerService                    | 219 - org.apache.activemq.activemq-osgi - 5.11.0.redhat-630187 | Apache ActiveMQ 5.11.0.redhat-630187 (amq, ID:AAXA22A747-54051-1506700691718-0:1) started
2017-09-29 11:58:11,934 | INFO  | AMQ-1-thread-1   | BrokerService                    | 219 - org.apache.activemq.activemq-osgi - 5.11.0.redhat-630187 | For help or more information please see: http://activemq.apache.org
2017-09-29 11:58:11,952 | INFO  | AMQ-1-thread-1   | ActiveMQServiceFactory           | 231 - io.fabric8.mq.mq-fabric - 1.2.0.redhat-630187 | Broker amq has started.

环境:

Java 8 JBoss的熔丝-6.3.0.redhat-187

1 个答案:

答案 0 :(得分:0)

显然,可以使用&#34; wrap&#34; 安装功能来安装第三方资源...

即,

这对我不起作用(可能是maven配置问题)

osgi:install wrap:mvn:org.json/json/20170516

为我工作(直接指向文件位置)

osgi:install -s wrap:file:C:/tools/json-20170516.jar