简体   繁体   English

将多个jar文件添加到jar的类路径

[英]Adding multiple jar files to class path of jar

I'm using the maven-antrun-plugin to do several things to a single deployable artifact after packaging. 打包后,我正在使用maven-antrun-plugin对单个可部署工件进行一些操作。 However, the package I'm using makes several assumptions about the class path of its own plugins which are not in any repository. 但是,我正在使用的软件包对自己的插件的类路径进行了一些假设,这些插件不在任何存储库中。 I've tried adding the plugin files to the jar, with no success. 我尝试将插件文件添加到jar中,但没有成功。 My next step is to let the plugins reside in a folder next to the jar file with the following structure: 我的下一步是让插件驻留在具有以下结构的jar文件旁边的文件夹中:

    .
    nutch2handler.jar
    plugins/
        plugin1/plugin1.jar
        plugin2/plugin2.jar
        plugin3/plugin3.jar
        etcetcetc

After antrun is done packaging the various artifacts(jar, plugins, www, shell scripts etc), it adds some configuration to the root of the jar for the same reason as above, and this works in this case. antrun完成打包各种工件(jar,插件,www,shell脚本等)的包装后,出于与上述相同的原因,它将一些配置添加到jar的根目录中,并且在这种情况下有效。 I know I can create a property hold a string containing a path I want to add to the classpath, but I don't want to type in all of these 20+ plugins into that property, as the plugin content may vary. 我知道我可以创建一个属性,该属性包含一个包含要添加到类路径的路径的字符串,但由于该插件的内容可能有所不同,因此我不想将所有这20多个插件都键入该属性。 How do I recursively add these jar files to that class-path? 如何将这些jar文件递归添加到该类路径?

I currently have 我目前有

    <property name="jar.class.path" value="" />

In my target configuration, and want to insert something like this with 在我的目标配置中,并希望使用

    <attribute name="Class-Path" value="${jar.class.path}"/>

Inside the jar tag. 在jar标签内。

If your nutch2handler.jar and all other pluigns are in folder named "lib": 如果您的nutch2handler.jar和所有其他插件都位于名为“ lib”的文件夹中:

you can define something like below to add all recursive jars to your classpath: 您可以定义以下内容,将所有递归jar添加到您的类路径中:

<path id="jar.class.path">
  <fileset dir="lib">
    <include name="**/*.jar" />
  </fileset>
</path>

and then you can use <classpath refid="jar.class.path" /> to refer to the property where ever necessary. 然后可以在必要时使用<classpath refid="jar.class.path" />引用该属性。

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

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