0

I have pom.xml like this:

<plugins>
              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                  <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>package.mainClass</mainClass>
                        <classpathPrefix>lib/</classpathPrefix>
                  </manifest>
                  </archive>
                </configuration>
              </plugin>
              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                <source>1.6</source>
                <target>1.6</target>
                </configuration>
              </plugin>
</plugins>

and I compile and package my project successful. but when I java -jar myProject.jar I get Error: Could not find or load main class package.mainClass!!

I think it happened because I wrote both mainClass and classpathPrefix in manifest! what is the way to set them with each other in pom.xml?

Ehsan Solimo
  • 23
  • 1
  • 9
  • `classpathPrefix` applies to the `dependencies` and not the project binaries and can co-exist with `mainClass`. From where are you running `java - jar ...` - I assume `target` folder? – Raghuram Aug 05 '15 at 10:34
  • yea exactly target folder! I must run from any other folder? – Ehsan Solimo Aug 05 '15 at 10:36
  • Can you open `MANIFEST.MF` in the project jar to see if `Main-Class` is the same as what you are trying to run? – Raghuram Aug 05 '15 at 10:48
  • yes it has my main class: `Manifest-Version: 1.0 Built-By: soltanmohammadi Build-Jdk: 1.7.0_45 Class-Path: D:/9405/todayJob/lib/OperationMaker-1.0.jar D:/9405/todayJ ob/lib/slf4j-api-1.7.12.jar D:/9405/todayJob/lib/logback-classic-1.0. 13.jar D:/9405/todayJob/lib/logback-core-1.0.13.jar Created-By: Apache Maven 3.0.5 Main-Class: first.PathGetter Archiver-Version: Plexus Archiver` first.PathGetter is my main class – Ehsan Solimo Aug 05 '15 at 10:53

1 Answers1

0

"Main-Class: first.PathGetter" instead of "Main-Class: package.mainClass" in pom.xml file, according to your MANIFEST.MF

ismailalabou
  • 37
  • 2
  • 8