引起:java.lang.ClassNotFoundException:com.myproject.core找不到net.sf.json.xml.XMLSerializer [35154]

时间:2014-02-11 18:43:44

标签: java json cq5 json-lib

我使用json-lib将xml结构转换为json格式。我的依赖关系看起来像这样:

 <dependencies>

        <dependency>
            <groupId>net.sf.json-lib</groupId>
            <artifactId>json-lib</artifactId>
            <version>2.4</version>
        </dependency>

        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.5</version>
        </dependency>

        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.3</version>
        </dependency>

        <dependency>
            <groupId>net.sf.ezmorph</groupId>
            <artifactId>ezmorph</artifactId>
            <version>1.0.6</version>
        </dependency>

        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>

        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>3.2.1</version>
        </dependency>

        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.8.0</version>
        </dependency>

        <!-- XML -->
        <dependency>
            <groupId>xom</groupId>
            <artifactId>xom</artifactId>
            <version>1.0</version>
        </dependency>

    </dependencies>

在以下行中:

 XMLSerializer xmlSerializer = new XMLSerializer();

编译器抛出了愚蠢的错误:

Caused by: java.lang.ClassNotFoundException: net.sf.json.xml.XMLSerializer not found by com.myproject.core

我知道为什么会收到此错误?

1 个答案:

答案 0 :(得分:0)

我通过将缺少的jar添加到maven-bundle-plugin嵌入依赖项

来解决问题
           <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Embed-Dependency>
                            ..
                            .....
                            json-lib,
                            xom,
                            ezmorph,
                            commons-collections,
                            commons-beanutils,
                            .....
                        </Embed-Dependency>
                  .............