user1801279
user1801279

Reputation: 1783

creating an executable jar using maven

I am trying to create an executable jar using maven . I had a java web project which i converted to maven using the m2e eclipse plug in . to create a runnable jar , my pom.xml is configured the following way .

<build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
      <resource>
        <directory>src</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>

    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>

    <!--  to create a runnable jar -->  
      <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <mainClass>com.test.main</mainClass> // main being main.java which has my main method
          </manifest>
        </archive>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
      </configuration>
    </plugin>

    </plugins>
  </build>

I then did edit->run as-> in the (edit configuration) tab I added "package" to the goals tab . The project builds successfully but when I try to run the jar I keep getting "no main manifest found " , where am I going wrong?

Upvotes: 0

Views: 3139

Answers (1)

Nathaniel Waisbrot
Nathaniel Waisbrot

Reputation: 24473

I think you missed binding the plugin to a lifecycle phase:

http://maven.apache.org/plugins/maven-assembly-plugin/usage.html#Execution:_Building_an_Assembly

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
          <archive>
             <manifest>
                <mainClass>com.test.main</mainClass> // main being main.java which has my main method
             </manifest>
          </archive>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id> <!-- this is used for inheritance merges -->
            <phase>package</phase> <!-- bind to the packaging phase -->
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      [...]
</project>

Upvotes: 1

Related Questions