0

I am attempting to create a 0.0.1-SNAPSHOT.jar file that I can run via the, "java -jar 0.0.1-SNAPSHOT.jar" command.

I have a java/selenium/testng/maven project.

I have my pom.xml set up to include:

<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>lib/</classpathPrefix>
                      <mainClass>mypackage.myclass</mainClass>
                   </manifest>
                </archive>
             </configuration>
          </plugin>
       </plugins>

</build>

The file myclass.java contains a main method.

I have various other packages and class files included on this project.

Even though I have specifed the mainClass attribute it's not being picked up. When I go to to run this jar file that is created I get the error:

$ java -jar 0.0.1-SNAPSHOT.jar
Error: Could not find or load main class mypackage.myclass

I have set the mainClass in the pom.xml as seen above.

When I pull the jar file apart with, "jar tf 0.0.1-SNAPSHOT.jar > output.txt" I notice that it's filled with nothing but dependencies. Absolutely none of my *.java files are anywhere. The jar does somehow contain a couple of sql files that I had attached to the resources directory however.

I have been scouring the internet for two days. Please can someone tell me what I'm doing wrong?

Anton
  • 761
  • 17
  • 40
  • 4
    Refer to http://stackoverflow.com/questions/10483180/maven-what-is-pluginmanagement, `` is nice, but, if you put the configuration inside it, you need a `` element as well. – Tunaki Dec 06 '16 at 20:13
  • I have the in there. I'm desperate man. I have followed the apache documentation to the letter (as far as I can tell) but can't get it to work. – Anton Dec 06 '16 at 20:14
  • 1
    Yes, but look at the linked question, your configuration is inside a `` element, so you have to have a second `` element using it. – Tunaki Dec 06 '16 at 20:15
  • @Tunaki okay, I removed the . – Anton Dec 06 '16 at 20:17
  • 1
    It... depends. There is nothing wrong with the configuration of the Jar Plugin, per se. I'm not sure you know what `` really means, so you should really refer to the linked question. But the idea is that it declares a plugin, but it does not use it. If you're really confused, just comment out the `` and `` block, and just have ``. [Look here, there is an example](https://maven.apache.org/shared/maven-archiver/examples/classpath.html#Make). – Tunaki Dec 06 '16 at 20:19
  • @Tunaki, yeah, I read it and that makes sense. (Maven is still new to me, learning as I go) – Anton Dec 06 '16 at 20:23
  • 1
    Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/129942/discussion-between-tunaki-and-will-byers). – Tunaki Dec 06 '16 at 20:25
  • @Tunaki, you were right. I had all my files in src\test\java instead of src\main\java. I moved them all and that made all the difference. – Anton Dec 07 '16 at 14:26

0 Answers0