创建带有弹簧依赖项的超级罐子 [英] creating an uber jar with spring dependencies

查看:83
本文介绍了创建带有弹簧依赖项的超级罐子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个应用程序überjar,但是由于对spring框架的依赖而遇到了问题.尤其是xml模式的名称空间是有问题的.您会收到臭名昭著的NamespaceHandler问题:

I'm trying to create an application über jar, but running into an issue due to a dependency on the spring framework. In particular, the namespaces for the xml schemas are problematic. You get the infamous NamespaceHandler problem:

Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/c]

要创建(简单的)超级罐子,请用蚂蚁创建捆绑罐子,但是如果您具有spring依赖项,那么这将不起作用,因为spring jars在其许多jar文件的META-INF目录中都有诸如spring.handlers,spring.schemas和spring.tooling之类的文件.我认为,名称空间的解析取决于这些文件.

For creating (simple) uber jars, Creating a bundle jar with ant, but this doesn't work if you have spring dependencies due to the fact that the spring jars have files such as spring.handlers, spring.schemas and spring.tooling in the META-INF directories of many of their jar files. The namespace resolution is dependent, I believe, on these files.

überjar似乎以某种方式包含了所有必需的文件,但是我猜运行时只看到一个文件.

The über jar seems to somehow contain all necessary files, but I'm guessing the runtime is seeing only one.

例如,我的超级jar的jar -tf显示(部分显示)

For example, a jar -tf of my uber jar shows (in part)

META-INF/spring.handlers
META-INF/spring.schemas
META-INF/spring.tooling
META-INF/license.txt
META-INF/notice.txt
META-INF/spring.factories
META-INF/spring.handlers
META-INF/spring.schemas
META-INF/spring.tooling
META-INF/license.txt
META-INF/notice.txt
META-INF/license.txt
META-INF/notice.txt
META-INF/spring.handlers
META-INF/spring.schemas
META-INF/spring.tooling
META-INF/license.txt
META-INF/notice.txt
META-INF/license.txt

所以:问题..是否有一种方法可以创建一个将弹簧罐捆绑在里面的uber-jar?我需要合并META-INF文件吗?任何人都具有使用蚂蚁构建进行文件合并的经验吗?

So: question.. is there a way to create an uber-jar that has the spring jars bundled inside? Do I need to merge the META-INF files? Anyone have experience doing file merger with ant builds?

推荐答案

好吧..这很痛苦.

<target name="make-bundle" depends="jar">
  <!-- retrieve the dependencies -->
  <ivy:retrieve conf="deploy" pattern="${dist.dir}/dependencies/[artifact].[ext]"/>

  <delete dir="${dist.dir}/dependencies/uber" failonerror="false" />
  <mkdir dir="${dist.dir}/dependencies/uber"/> 
  <!-- iterate over the dependencies -->
  <for param="file">
    <path>
      <fileset dir="${dist.dir}/dependencies"> 
        <include name="**/*.jar"/> 
      </fileset> 
    </path>
    <sequential> 
      <propertyregex override="yes" 
        property="jarname"  input="@{file}" 
        regexp=".*/([^/]*)\.jar" replace="\1"/> 

      <!-- put the spring.* jars into special sub-directories -->
      <mkdir dir="${dist.dir}/dependencies/${jarname}"/> 
      <unzip dest="${dist.dir}/dependencies/${jarname}" src="@{file}">
        <patternset>
          <include name="**/META-INF/spring.*"/>
        </patternset>
      </unzip>
      <!-- put everything else in the 'uber' directory -->
      <unzip dest="${dist.dir}/dependencies/uber" src="@{file}">
        <patternset>
          <exclude name="**/META-INF/spring.*"/>
        </patternset>
        </unzip>
    </sequential>
  </for>

  <!-- build the concatenated spring.* files -->
  <mkdir dir="${dist.dir}/dependencies/META-INF"/> 
  <concat destfile="${dist.dir}/dependencies/META-INF/spring.handlers" fixlastline="true">
    <fileset dir="${dist.dir}/dependencies/" includes="*/*/spring.handlers"/>
  </concat>
  <concat destfile="${dist.dir}/dependencies/META-INF/spring.schemas" fixlastline="true">
    <fileset dir="${dist.dir}/dependencies/" includes="*/*/spring.schemas"/>
  </concat>
  <concat destfile="${dist.dir}/dependencies/META-INF/spring.tooling" fixlastline="true">
    <fileset dir="${dist.dir}/dependencies/" includes="*/*/spring.tooling"/>
  </concat>
  <concat destfile="${dist.dir}/dependencies/META-INF/spring.factories" fixlastline="true">
    <fileset dir="${dist.dir}/dependencies/" includes="*/*/spring.factories"/>
  </concat>

  <!-- build the uber jar! -->
  <delete file="${dist.dir}/myproject-with-dependencies.jar" failonerror="false"/>
  <jar destfile="${dist.dir}/myproject-with-dependencies.jar">
    <!-- all dependency files except spring.* -->
    <fileset dir="${dist.dir}/dependencies/uber"/> 
    <!-- the spring.* files -->
    <fileset dir="${dist.dir}/dependencies/" includes="META-INF/*"/>
    <!-- my project's classes & etc -->
    <zipgroupfileset dir="${dist.dir}" includes="myproject.jar" />
    <manifest>
      <attribute name="Main-Class" value="${main.class}"/>
    </manifest>  
  </jar>
</target>

这篇关于创建带有弹簧依赖项的超级罐子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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