0

I have a project which works perfectly on eclipse, but when I try to run it on terminal using jar file then I get an error. Basically, the aim is to create a fat jar with all dependencies included.

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.scryAnalytics</groupId>
    <artifactId>NLPAnnotationController</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

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

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <hadoop.version>2.6.0-cdh5.5.1</hadoop.version>
        <jdk.version>1.7</jdk.version>
        <hbase.version>1.0.0-cdh5.5.1</hbase.version>
    </properties>

    <repositories>
        <repository>
            <id>cloudera</id>
            <url>https://repository.cloudera.com/cloudera/cloudera-repos</url>
                </repository>
                 <repository>
                        <id>maven</id>
                        <url>https://repository.apache.org/content/</url>
                </repository>

        </repositories>


    <dependencies>


<dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-hdfs</artifactId>
                <version>2.6.0-cdh5.5.1</version>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-auth</artifactId>
                <version>2.6.0-cdh5.5.1</version>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-common</artifactId>
                <version>2.6.0-cdh5.5.1</version>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-yarn-api</artifactId>
                <version>2.6.0-cdh5.5.1</version>
            </dependency>
    <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-mapreduce-client-app</artifactId>
                <version>2.6.0-cdh5.5.1</version>
            </dependency>
<dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-mapreduce-client-common</artifactId>
                <version>2.6.0-cdh5.5.1</version>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-mapreduce-client-core</artifactId>
                <version>2.6.0-cdh5.5.1</version>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>


<artifactId>hadoop-yarn-client</artifactId>
            <version>2.6.0-cdh5.5.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hbase</groupId>
            <artifactId>hbase-client</artifactId>
            <version>1.0.0-cdh5.5.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hbase</groupId>
            <artifactId>hbase-common</artifactId>
            <version>1.0.0-cdh5.5.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hbase</groupId>
            <artifactId>hbase-server</artifactId>
            <version>1.0.0-cdh5.5.1</version>
        </dependency>
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-core-asl</artifactId>
        <version>1.9.13</version>
    </dependency>

    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.9.13</version>
    </dependency>


    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.10</version>
        <scope>test</scope>
    </dependency>



    <dependency>
        <groupId>uk.ac.gate</groupId>
        <artifactId>gate-core</artifactId>
        <version>8.1</version>
    </dependency>
    <dependency>
        <groupId>uk.ac.gate</groupId>
        <artifactId>gate-compiler-jdt</artifactId>
        <version>4.3.2-P20140317-1600</version>
    </dependency>

    <dependency>
        <groupId>com.thoughtworks.xstream</groupId>
        <artifactId>xstream</artifactId>
        <version>1.4.8</version>
    </dependency>

    <dependency>
        <groupId>jdk.tools</groupId>
        <artifactId>jdk.tools</artifactId>
        <version>${jdk.version}</version>
        <scope>system</scope>
        <systemPath>${java.home}/../lib/tools.jar</systemPath>
    </dependency>

    <dependency>
        <groupId>org.jsoup</groupId>
        <artifactId>jsoup</artifactId>
        <version>1.8.3</version>
    </dependency>
    <dependency>
        <groupId>com.scryAnalytics</groupId>
        <artifactId>NLPGeneric</artifactId>
        <version>1.1</version>
    </dependency>
    <dependency>
        <groupId>NER</groupId>
        <artifactId>NER</artifactId>
        <version>1.2</version>
    </dependency>

</dependencies>

    <build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.5.5</version>
            <configuration>
                <finalName>NLPAnnotationController</finalName>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>com.scryAnalytics.NLPAnnotationController.GateNLPJob</mainClass>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>conf</directory>
        </resource>
    </resources>
</build>

and when I run it I get the error shown below.

java -jar target/NLPAnnotationController-jar-with-dependencies.jar -inputTable posts -outputTable posts -batchId 1
Error: Invalid or corrupt jarfile target/NLPAnnotationController-jar-with-dependencies.jar
wadhwasahil
  • 468
  • 7
  • 28

1 Answers1

0

As suggested in a comment, double-check to see if the JAR file is really corrupt using jar tv <filename.jar>.

There are a couple of common causes for corrupt JAR files:

The first three explanations are unlikely in your case, for various reasons. That leaves a Maven plugin problem. One of the Q&As that I found said that this was fixed in version 2.5 of the maven-assembly-plugin. But you appear to be using a later version. So maybe this is not the problem after all.

Anyhow:

  • Check that you are using a Java 7 or later JRE or JDK on your build and execution platforms.
  • Try updating the version of the maven assembly plugin in your POM to the latest available.
Community
  • 1
  • 1
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216