简体   繁体   English

Maven源插件-如何仅为要包含的类生成源jar

[英]Maven Source Plugin - How do I generate the source jar for ONLY the classes I want included

Currently, the project I am working on has all of the code for the web service in a single and is creating a war and a jar file. 当前,我正在处理的项目将Web服务的所有代码都集成在一个文件中,并且正在创建war和jar文件。

The Jar file only contains the bare minimum of classes shared by other projects. Jar文件仅包含其他项目共享的最少类。
I don't have the option to split the shared classes out into a separate core project at this time. 我目前无法选择将共享类拆分为一个单独的核心项目。 (Though I would prefer that) (尽管我更喜欢)

I'm trying to put only the necessary java files in the source jar: 我试图将仅必要的java文件放在源jar中:

Common_Model-1.1.2.jar  
Common_Model-1.1.2.jar-sources

I have something like this in my POM: 我的POM中有这样的内容:

<plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.3.2</version>
    <executions>
      <execution>
        <goals>
          <goal>jar</goal>
        </goals>
        <configuration>
          <includes>
            <include>gov/app/api/common/models/**</include>
            <include>gov/app/api/intra/models/**</include>
            <include>gov/app/api/models/**</include>
          </includes>
          <finalName>Common_Model-1.1.2</finalName>
        </configuration>
      </execution>
    </executions>
</plugin>
<plugin>
    <artifactId>maven-source-plugin</artifactId>
    <executions>
      <execution>
        <goals>
          <goal>jar</goal>
        </goals>
        <configuration>
          <includes>
            <include>gov/app/api/common/models/**</include>
            <include>gov/app/api/intra/models/**</include>
            <include>gov/app/api/models/**</include>
          </includes>
          <finalName>Common_Model-1.1.2</finalName>
        </configuration>
      </execution>
    </executions>
</plugin>

While this does create the sources jar, it ignores the includes configuration and adds all of the .java files from the entire project. 尽管这确实创建了源jar,但它忽略了include配置并添加了整个项目中的所有.java文件。

I've also tried using <excludes> , but that too is ignored. 我也尝试过使用<excludes> ,但这也被忽略了。

I tried this in my project: 我在我的项目中尝试过:

<include>com/sandbox/**/Permutations*</include>

And the resulting Common_Model-1.1.2-sources.jar only had this one file in it named Permutations.java When I tried 当我尝试时,生成的Common_Model-1.1.2-sources.jar中只有一个名为Permutations.java的文件。

<include>com/sandbox/Permutations*</include>
<include>com/sandbox/Sandbox*</include>

The jar had only those two files. 罐子只有两个文件。 So what you've got should work. 因此,您所拥有的应该可以工作。 I suspect your patterns are too broad. 我怀疑您的模式太宽泛了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Maven - 如何为测试包创建源jar? - Maven - How do I create source jar for test package? 如何将其他源目录添加到 maven 以生成 javadoc? - How do I add additional source directories to maven to generate javadoc? Maven - 如何在使用 maven-source-plugin 生成的.jar 文件中包含 jsp 文件 - Maven - How can I include jsp files in the .jar file generated using maven-source-plugin 如何用Maven中的源码生成一个JAR - How to generate a JAR with the source code in Maven 如何为我没有源代码的.jar文件中的类生成JavaDoc文档? - How to generate JavaDoc documentation for classes in a .jar file that I don't have the source code for? Maven Jar插件和Maven源插件用法 - Maven Jar Plugin and Maven Source Plugin Usage 如何使用jaxb2-maven-plugin在源文件夹中生成java类? - How to generate java classes into source folder using jaxb2-maven-plugin? 如何配置axis2-java2wsdl-maven-plugin以使用多个类来生成一个wsdl? - How do I configure axis2-java2wsdl-maven-plugin to use multiple classes to generate one wsdl? 如何使用 OpenApi maven 插件生成多个 api 类? - How can I generate several api classes with OpenApi maven plugin? 如何添加将由maven-jxr-plugin使用的额外源目录? - How do I add an extra source directory that will be used by the maven-jxr-plugin?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM