0

I'm creating a runnable JAR with maven and all works fine. With assembly i include my libs on external folder but when i run it my application start and at some point i get NoClassDefFoundError This class is org.json.JSONException.

I'm using this library that require JSON classes. I've tried to clone the repository and build it because i have had to make some changes.

When i run my project from Eclipse all works fine, no error and application works. But, when i run it from JAR executable i got this error.

Looking in the repository i've noticed that this use json artifact, so i have included it in my pom.xml but without results....

All others library are loaded correctly.

This is the build phase of the pom.xml (i have omitted dependencies, if will be necessary i'll include too)

<build>
    <plugins>
        <plugin>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <archive>
                    <!-- Make an executable jar, adjust classpath entries-->
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>./lib/</classpathPrefix>
                        <mainClass>it.mypkg.MyMainClass</mainClass>
                    </manifest>
                    <!--Resources will be placed under conf/-->
                    <manifestEntries>
                        <Class-Path>./conf/</Class-Path>
                    </manifestEntries>
                </archive>
                <!--exclude the properties file from the archive-->
                <excludes>
                    <exclude>*.properties</exclude>
                </excludes>
            </configuration>
        </plugin>

        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.2-beta-5</version>
            <configuration>
                <descriptors>
                    <descriptor>${basedir}/assembly/distribution-zip.xml</descriptor>
                </descriptors>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        </plugins>
    </build>

And this is the assembly (both configuration come from another stackoverflow thread):

<assembly>
    <id>dist</id>
    <formats>
        <format>zip</format>
    </formats>

    <includeBaseDirectory>true</includeBaseDirectory>

    <dependencySets>
        <dependencySet>
            <!--Include runtime dependencies-->
            <outputDirectory>lib</outputDirectory>
            <scope>runtime</scope>
        </dependencySet>
    </dependencySets>

    <fileSets>
        <fileSet>
            <!--Get the generated application jar-->
            <directory>${project.build.directory}</directory>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>*.jar</include>
            </includes>
        </fileSet>
        <fileSet>
            <!--Get application resources-->
            <directory>src/main/resources</directory>
            <outputDirectory>conf</outputDirectory>
        </fileSet>
        <fileSet>
            <!--Get misc user files-->
            <directory>${project.basedir}</directory>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>README*</include>
                <include>LICENSE*</include>
                <include>NOTICE*</include>
            </includes>
        </fileSet>       
    </fileSets>
</assembly>

EDIT: I add dependecy list because i've noticed that when i remove json dependency in my pom.xml i got the same error. Json dependency is not needed for my project but is used in the link i've provided you above.

When i remove json project dont work in Eclipse When i add json project works in Eclipse With or without Json library, project dont works as runnable JAR (is missing that dependency - json)

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-integration</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-xml</artifactId>
            <version>4.2.4.RELEASE</version>
            <scope>compile</scope>  
        </dependency>

        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-ws</artifactId>
            <version>4.2.4.RELEASE</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.0.0.0</version>
        </dependency>

        <!-- Uses Castor for XML -->
        <dependency>
            <groupId>org.codehaus.castor</groupId>
            <artifactId>castor</artifactId>
            <version>1.2</version>
        </dependency>

        <!-- Castor need this -->
        <dependency>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
            <version>2.8.1</version>
        </dependency>

        <dependency>
            <groupId>org.fusesource</groupId>
            <artifactId>sigar</artifactId>
            <version>1.6.4</version>
        </dependency>

        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>2.11.0</version>
        </dependency>

        <dependency>
            <groupId>parse</groupId>
            <artifactId>parse4j</artifactId>
            <version>1.5</version>
        </dependency>

        <!--  
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.5</version>
        </dependency>
         -->

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.3.2</version>
        </dependency>  

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <version>4.3.1</version>
        </dependency>   

        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20160212</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.9</version>
        </dependency>   

    </dependencies>
Mistre83
  • 2,677
  • 6
  • 40
  • 77
  • Dont think this is a duplicate of that thread... i've a problem just with one library, all others library works fine... – Mistre83 Jun 04 '16 at 20:00
  • Without a full pom file and the commands you have used it's impossible to guest what's wrong.. – khmarbaise Jun 04 '16 at 20:06
  • edited with pom and assembly config – Mistre83 Jun 04 '16 at 20:31
  • @Mistre83 I see you are using maven assembly plugin. which is also an beta version. Can you try the solution mentioned here? http://stackoverflow.com/questions/37596779/how-to-make-jar-file-independent/37608076#37608076 – Vijendra Kumar Kulhade Jun 04 '16 at 23:19
  • First you should use uptodate versions of plugins and not extremely old versions of plugins (maven-assembly-plugin 2.6, maven-jar-plugin 2.6 or 3.0.0)..Furthermore what you need is a `jar-with-dependencies`. The configuration be found here: http://maven.apache.org/plugins/maven-assembly-plugin/usage.html – khmarbaise Jun 05 '16 at 10:12

0 Answers0