Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
274 views
in Technique[技术] by (71.8m points)

Use extracted java sources to compile with maven

I'm using maven-dependency-plugin to extract some classes from a big jar and add them to my project classes. Right no, there 2 jars, each build with a classifier: sources and helper. The sources jar has all java files. The helper jar has most of the classes (classes no java files) of complete dependency.

Since I need the missing classes, I would like to extract all java files from "sources"-classifier-jar to target/extracted/src instead of the classes from "helper"-classifier-jar to target/classes, and compile them. Since my project depends on the compiled classes I'm running the dependency-plugin during generate-sources-phase.

Does anybody have an idea how I could achieve this? What am I doing wrong? I have tried adding a source-directory (which would be the output directory of the dependency-plugin) with the compiler-plugin, but I can't build the project. It doesn't find the classes.

<plugin>
  <artifactId>mave-dependency-plugin>
  <executions>
    <execution>
      <configuration>
        <artifactItems>
          <artifactItem>
            <gropuId>...</groupId>
            <artifactId>...</artifactId>
            <version>1.0</version>
            <includes>
              com/acme/Bar.java
            </includes>
            <overWrite>false</overWrite>
            <type>jar</type>
          </artifactItem>
       </artifactItems>
       <outputDirectory>${project.build.directory}/extracted/src</outputDirectory>
      </configuration>
      <goals>
        <goal>unpack</goal>
      </goals>
      <id>unpack</id>
      <phase>generate-sources</phase>
    </execution>
  </executions>
</plugin>      
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>build-helper-maven-plugin</artifactId>
  <version>3.2.0</version>
  <executions>
     <execution>
     <id>add-source</id>
     <phase>generate-sources</phase>
     <goals>
        <goal>add-source</goal>
     </goals>
     <configuration>
       <sources>
        <source>${project.build.directory}/extracted/src</source>
       </sources>
     </configuration>
   </execution>
  </executions>
</plugin>

Somewhere in my project java classes I have a reference to Bar.class e.g.

import com.acme.Bar;

I would appreciate any helpful hint.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...