Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven AppAssembler not finding class

Attempting to modify an existing Java/Tomcat app for deployment on Heroku following their tutorial and running into some issues with AppAssembler not finding the entry class. Running target/bin/webapp (or deploying to Heroku) results in Error: Could not find or load main class org.stopbadware.dsp.Main

Executing java -cp target/classes:target/dependency/* org.stopbadware.dsp.Main runs properly however. Here's the relevant portion of pom.xml:

  <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>appassembler-maven-plugin</artifactId>
      <version>1.1.1</version>
      <configuration>
          <assembleDirectory>target</assembleDirectory>
          <programs>
              <program>
                  <mainClass>org.stopbadware.dsp.Main</mainClass>
                  <name>webapp</name>
              </program>
          </programs>
      </configuration>
      <executions>
          <execution>
              <phase>package</phase>
              <goals>
                  <goal>assemble</goal>
              </goals>
          </execution>
      </executions>
    </plugin>

My guess is mvn package is causing AppAssembler to not use the correct classpath, any suggestions?

like image 518
frostmatthew Avatar asked Mar 05 '13 16:03

frostmatthew


2 Answers

Your artifact's packaging must be set to jar, otherwise the main class is not found.

<pom>
  ...
  <packaging>jar</packaging>
  ...
</pom>

The artifact itself is added at the end of the classpath, so nothing other than a JAR file will have any effect.

like image 141
Mwanji Ezana Avatar answered Sep 21 '22 23:09

Mwanji Ezana


Try:

mvn clean package jar:jar appassembler:assemble
like image 35
Renaud Avatar answered Sep 20 '22 23:09

Renaud