Create two jar with the same pom by the eclipse

1

How to create a pom in the maven that generates by eclipse two .JAR files, where one will have the .class files and the other .jar will have the sources (.java files) doing only one install. Example:

Project

exemplo.jar
exemplo-src.jar

Example of my build:

<build>
  <sourceDirectory>src</sourceDirectory>
  <resources>
    <resource>
      <directory>src</directory>
      <excludes>
        <exclude>**/*.java</exclude>
      </excludes>
    </resource>
  </resources>
  <finalName>${project.artifactId}-${project.version}</finalName>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <executions>

        <execution>
          <id>copy-installed</id>
          <phase>install</phase>
          <goals>
            <goal>copy</goal>
          </goals>
          <configuration>
            <artifactItems>
              <artifactItem>
                <groupId>${project.groupId}</groupId>
                <artifactId>${project.artifactId}</artifactId>
                <version>${project.version}</version>
                <type>${project.packaging}</type>
              </artifactItem>
            </artifactItems>
            <outputDirectory>build/deploy</outputDirectory>
          </configuration>
        </execution>         
      </executions>
    </plugin>

    <plugin>
      <version>3.0</version>
      <artifactId>maven-compiler-plugin</artifactId>
      <configuration>
        <source>1.7</source>
        <target>1.7</target>
        <encoding>iso-8859-1</encoding>
            <showDeprecation>true</showDeprecation>
            <showWarnings>true</showWarnings>
      </configuration>
    </plugin>

  </plugins>
</build> 
    
asked by anonymous 25.03.2015 / 22:00

2 answers

0

Maven has a plugin specialized in generating jar files with the project sources (production source code or tests), Maven Source Plugin .

To generate a jar with the project production source code (.java files), simply configure this plugin in your current list of plugins:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <executions>
        <execution>
            <id>attach-sources</id>
            <goals>
                <goal>jar</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Now invoking mvn install will also generate a exemplo-version-sources.jar jar.

See more options for this plugin here .

    
26.03.2015 / 13:42
1

For those who find my persistent question I found an optimized solution. I type the content below into the pom, and write

mvn clean source:jar package

Note that when you create the project there is already a <package> tag, you do not need to announce it, and if you do not choose any package it will create the jar by default.

<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
  <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
      <source>1.7</source>
      <target>1.7</target>
    </configuration>
  </plugin>
  <plugin>
    <version>2.7</version>
    <artifactId>maven-deploy-plugin</artifactId>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
    </configuration>
  </plugin>
</plugins>

    
07.05.2015 / 01:10