gpt4 book ai didi

spring - 创建一个具有 spring 依赖项的 uber jar

转载 作者:行者123 更新时间:2023-12-01 10:47:58 27 4
gpt4 key购买 nike

我正在尝试创建一个 über jar 应用程序,但由于依赖于 spring 框架而遇到问题。特别是,xml 模式的 namespace 存在问题。你遇到了臭名昭著的 NamespaceHandler 问题:

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

用于创建(简单的) super jar ,Creating a bundle jar with ant ,但如果您有 spring 依赖项,这将不起作用,因为 spring jar 在其许多 jar 文件的 META-INF 目录中具有 spring.handlers、spring.schemas 和 spring.tooling 等文件。我相信命名空间解析取决于这些文件。

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

例如,我的 uber jar 的一个 jar -tf 显示(部分)

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

所以:问题.. 有没有一种方法可以创建一个将 spring jar 捆绑在里面的 super jar ?我需要合并 META-INF 文件吗?任何人都有使用 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>

关于spring - 创建一个具有 spring 依赖项的 uber jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23574979/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com