简体   繁体   English

创建一个用Maven构建的项目的jar?

[英]Creating a jar of a project built with maven?

I have a maven project in which (under src/main/java) i have many packages and (but there is only one central pom.xml) Each package provides a different functionality than the other. 我有一个Maven项目,其中(在src / main / java下)我有许多软件包,并且(但只有一个中央pom.xml)每个软件包提供的功能与另一个软件包不同。 So now i need to create a jar file of one particular package.If it was a normal java package(ie not built with maven) ,I would have simply extracted that package(using Export in eclipse and then selecting java->jar option) but i cant figure out a way to do this with maven. 所以现在我需要创建一个特定程序包的jar文件。如果它是一个普通的Java程序包(即不是用maven构建的),我将简单地提取该程序包(使用eclipse中的Export,然后选择java-> jar选项)但我想不出一种用Maven做到这一点的方法。 I also checked out Apache Maven Assembly Plugin but i couldn't figure out how to fit that plugin in my scenario. 我还检查了Apache Maven Assembly Plugin,但我不知道如何在我的方案中安装该插件。 I am new at maven so kindly help me out. 我是maven的新手,请帮助我。 Thanks 谢谢

Use Maven jar plugin: 使用Maven jar插件:

<project>
  ...
  <build>
    <plugins>
      ...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.5</version>
        <configuration>
          <includes>
            <include>**/service/*</include>
          </includes>
        </configuration>
      </plugin>
      ...
    </plugins>
  </build>
  ...
</project>

Best in Maven is to create a multi module build for each part you would like to have a separate module which creates it's own jar. 在Maven中最好的做法是为每个要创建一个自己的jar的单独模块创建一个多模块构建。 This will make it easy to separate functionality as well according tests. 这也使根据测试轻松分离功能变得容易。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM