我正在尝试创建一个应用程序überjar,但由于依赖于spring框架而遇到了问题。特别是,xml架构的命名空间是有问题的。你得到了臭名昭着的NamespaceHandler问题:
Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/c]
用于创建(简单)超级罐Creating a bundle jar with ant,但如果由于spring jar有spring.handlers,spring.schemas和spring等文件而有弹簧依赖性,这不起作用。在许多jar文件的META-INF目录中加工。我认为,命名空间解析依赖于这些文件。
überjar似乎以某种方式包含所有必需的文件,但我猜测运行时只看到一个。
例如,我的超级罐的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
所以:问题..是否有办法创建一个内部装有弹簧罐的超级罐?我需要合并META-INF文件吗?任何人都有与蚂蚁构建文件合并的经验吗?
答案 0 :(得分:6)
<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>