0

I'm using Maven to build a project I'm working on. The build works fine, the problem happens when I run the generated JAR. The error says the main class com.apress.springrecipes.sequence.Main cannot be found. But looking at the folder structure I'm not seeing why the Main class can't be found.

Here's the folder structure:

myJar.jar
    --com
        --apress
            --springrecipes
                --sequence
                    --Main.class
    --META-INF
        --MAINIFEST.MF

The MANIFEST.MF file has the main class attribute set to com.apress.springrecipes.sequence.Main. But it looks like the JAR can't find it even though the class file is located in the JAR.

Here's the relevant portion of my pom.xml that handles the build:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>C:/Users/Graham/.m2/repository/</classpathPrefix>
                        <classpathLayoutType>repository</classpathLayoutType>
                        <mainClass>com.apress.springrecipes.sequence.Main</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

Why isn't the Main class being found in the jar even though it's there?

Graham
  • 5,488
  • 13
  • 57
  • 92
  • How does your genersted manifest look like? – René Winkler Mar 12 '15 at 17:17
  • Please check this question. http://stackoverflow.com/questions/1814526/problem-building-executable-jar-with-maven. You can use maven assembly to generate an executable JAR. Hope this helps. – ArunM Mar 23 '15 at 11:01

2 Answers2

0

I'm not a Java dev, but I give it a try: what the compiler says and what you're checking is not the same thing. The compiler says it cannot find the "Main class", it does not say it cannot find the "Main.class file".

The file may be there, but is there a "class Main..." defined in it (with a public void main() method)?

0xFC
  • 161
  • 2
0

Even I was facing similar issue, I took below actions and it worked.

  1. Make sure your IDE and the JAVA_HOME environment variable are pointing to the same version of JAVA.
  2. If you have any configuration files (.ini, xml etc) place those along with the JAR file in the same folder.