Maven:我可以只在罐子中打包依赖项(不带应用程序)吗? [英] Maven: Can I package only dependencies(without app) in a jar?

查看:104
本文介绍了Maven:我可以只在罐子中打包依赖项(不带应用程序)吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个旧版JAVA项目,该项目使用ant进行构建.由于该项目中的jar依赖项管理确实很繁琐,因此我计划集成maven.

I have a legacy JAVA project which uses ant for builds. Since jar dependency management in this project is really tedious, I am planning to integrate maven.

我试图仅将maven用于依赖项管理,并继续使用ant进行构建.我正在考虑使用maven生成一个jar,它将包含所有依赖项,然后将这个jar包含在我的应用的类路径中.

I am trying to use maven only for dependency management and keep using ant for builds. I am contemplating to produce a single jar using maven which will contain all the dependencies and then I will include this single jar in classpath of my app.

我知道这可能不是最好的方法,但是有可能这样做吗? 有什么更好的方法?

I know this might not be the best approach but is it possible to do this? What might be a better approach?

推荐答案

我将创建一个pom.xml文件(包含所有必填字段,例如groupId,artifactId ...),然后将所有依赖项添加到此pom中,并添加这个pom的maven程序集插件.执行mvm assembly:single命令.将创建具有所有依赖项的jar.

I would create a pom.xml file (with all the required fields, like groupId, artifactId ...) add all the dependencies to this pom, and add maven assembly plugin to this pom. execute mvm assembly:single command. Your jar with all the dependencies will be created.

<build>
  <plugins>
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>    
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
      </configuration>
    </plugin>
  </plugins>
</build>

这篇关于Maven:我可以只在罐子中打包依赖项(不带应用程序)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆