9

I am using maven assembly plug in to package my project with all its dependency so i can run a simple java -jar myproject.jar and be able to run the project. However when I ran the jar it told me

Error: Could not find or load main class com.project.ServerStart

Then I unzipped the .jar file and found that the assembly does not include my project files, which is ridiculous !
When packaging the project I receive this warning

[WARNING] Cannot include project artifact: Amjar:amjar:pom:0.2; it doesn't have an associated file or directory.

This is my plugin config

<build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <finalName>amjar-${project.version}</finalName>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
              <mainClass>com.project.ServerStart</mainClass>
            </manifest>
          </archive>
        </configuration>
        <executions>
          <execution>
            <id>assemble-all</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

What am I doing wrong ?

Adelin
  • 18,144
  • 26
  • 115
  • 175
  • try to look on that answer http://stackoverflow.com/a/574650/1370062 – RMachnik May 21 '14 at 08:35
  • I didn't work for I've already configured my pom.xml as the answer says but, still getting the error ! – Adelin May 21 '14 at 08:44
  • the same error you get? – RMachnik May 21 '14 at 08:44
  • are you sure that you have `com.project.ServerStart` on classpath? – RMachnik May 21 '14 at 08:45
  • Can you explain e little more ? what do you mean on the classpath ? and how can I make sure of it ? I am using Ubuntu 13.04 do you want me to add all my project classes to $PATH variable ? – Adelin May 21 '14 at 08:52
  • Nooo... not to `Path` but to `classpath` do you have `ServerStart` class in your project? because that plugin search for it, in your case it is not there so there is error. You have to have that class in your code so simply on `classpath` or change it to another `class` that have `main method`. – RMachnik May 21 '14 at 08:55
  • of course I do have this class in my code and it has a main method as well. I really don't know what could be the problem. – Adelin May 21 '14 at 09:02
  • What is the `packaging` set to in your `pom.xml`? I needs to be set to `jar` – Nick Holt May 21 '14 at 09:04
  • Yes it worked .. the problem was the packaging. Please provide your comment as an answer so I can vote it. And Thanks a lot – Adelin May 21 '14 at 09:12

1 Answers1

12

From the warning you've included in your question:

[WARNING] Cannot include project artifact: Amjar:amjar:pom:0.2; it doesn't have an associated 

I'd guess that you've got the packaging in your pom.xml set to pom.

This is fine if your module is simply packaging a set of dependencies or resource files, however, if you also want Maven to create a jar containing the classes in you module you will need to set the packaging to jar.

Nick Holt
  • 33,455
  • 4
  • 52
  • 58