Maven: Can I package only dependencies(without app) in a jar?

非 Y 不嫁゛ 提交于 2019-12-11 06:04:44

问题


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.

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?


回答1:


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>


来源:https://stackoverflow.com/questions/48790400/maven-can-i-package-only-dependencieswithout-app-in-a-jar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!