lunes, 8 de abril de 2013

Maven & Aplicaciones Standalone (JARs)

Ver este link:

http://maven.apache.org/plugins/maven-jar-plugin/examples/manifest-customization.html

If you want to make a standalone jar (ie one with no dependencies) executable, here’s how you do it:

<plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
        <configuration>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
              <mainClass>com.yourcompany.YourClass</mainClass>
            </manifest>
         </archive>
       </configuration>
    </plugin>
  </plugins>

If however you have dependencies, you will probably want to bundle them into a single jar, otherwise making it executable is not very helpful. You can use the assembly plugin to do it like this:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-assembly-plugin</artifactId>
    <executions>
      <execution>
         <goals>
           <goal>attached</goal>
         </goals>
         <phase>package</phase>
         <configuration>
           <descriptorRefs>
             <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
          <archive>
            <manifest>
              <mainClass>com.yourcompany.YourClass</mainClass>
            </manifest>
          </archive>
        </configuration>
     </execution>
  </executions>
</plugin>

De esta menera, ademas de crear el JAR sin dependencias vamos a ver que nos crea un JAR con dependencias donde todas las dependencias las agrega como clases (prueba-tools-1.0-SNAPSHOT-jar-with-dependencies.jar).