Create two jar with the same pom by eclipse

Asked

Viewed 259 times

1

How to create a pom in the Maven that manages by eclipse two files. Jars, where one will have the files . class 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> 

2 answers

1

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

mvn clean source:jar package

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

<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>

0


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

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

<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, on the call mvn install, a jar will also be generated exemplo-version-sources.jar.

See more options of this plugin here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.