-1

I am having problem running a jar from shell command as i keep on getting "could not find or load main class error"

After dropping the jar file into my server. I execute following command

java -jar mapr.jar

But i get an error saying - could not find or load main class

Below is my project structure -

mapreduce (projectname)
 --src/main/java
    --mapreduce (packagename)
       --Map.java
          --ZipProcessor.java (main Class)

and my POM.xml file -

<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.project.hadoop</groupId>
    <artifactId>mapreduce</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>MapReduce</name>

    <dependencies>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-common</artifactId>
            <version>2.5.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-mapreduce-client-common</artifactId>
            <version>2.5.0</version>
        </dependency>
    </dependencies>


    <build>
        <finalName>mapr</finalName>
        <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>ZipProcessor</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
     </plugins>
    </build>

</project>

I got my problem resolved using below plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <archive>
                <manifest>
                <addClasspath>true</addClasspath>
                <classpathPrefix>lib/</classpathPrefix>
                    <mainClass>
                        com.application.ZipProcessor
                    </mainClass>
                </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
        </execution>
    </executions>
</plugin>
Jon Abraham
  • 851
  • 3
  • 14
  • 27
  • How did you create this JAR file? It sounds to me like the JAR's manifest is referring to a class which is not present, that's all. – Tim Biegeleisen Feb 27 '19 at 05:13
  • 1
    Possible duplicate of [Maven Error: Could not find or load main class](https://stackoverflow.com/questions/29366373/maven-error-could-not-find-or-load-main-class) – ilinykhma Feb 27 '19 at 05:45
  • Build using command prompt and resolve those error first – Dhanraj Feb 27 '19 at 05:56

1 Answers1

3
<manifest>
     <mainClass>ZipProcessor</mainClass>
</manifest>

The above declaration of your main class should be done including package name and the class name.

If your package name is com.test.processor and your class name is App then the above declaration of main class should be as below :

<manifest>
     <mainClass>com.test.processor.App</mainClass>
</manifest>

Hope this resolves your issue.

Abhishek
  • 2,485
  • 2
  • 18
  • 25