使用ant编译Spring Boot应用程序时出错



我正试图用AntLib编译一个Spring Boot+Batch项目,因为在CI Jenkins中是这样配置的。

当编译项目时,会产生一个错误"/ext-lib/spring-bot-antlib-2.4.0.jar/org/springframework/boot/ant/antlib.xml:27:java.lang.NoClassDefFoundError:org/springframework/util/StringUtils">

build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="gprd-logs-cleaner" default="main" basedir="."
xmlns:au="antlib:org.apache.ant.antunit" 
xmlns:spring-boot="antlib:org.springframework.boot.ant" 
xmlns:ivy="antlib:org.apache.ivy.ant">
<property name="src.dir" location="src/main/java" />
<property name="resource.dir" location="src/main/resources" />
<property name="target.dir" location="target" />
<property name="classes.dir" location="${target.dir}/classes" />
<property name="lib.dir" value="lib" />
<property name="main-class" value="com.gprd.logs.cleaner.CCCLogsCleanerApp" />
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant" classpath="${ivy.class.path}"/>
<taskdef resource="org/apache/ant/antunit/antlib.xml"
uri="antlib:org.apache.ant.antunit" classpath="${antunit.class.path}"/>
<path id="classpath">
<fileset dir="${basedir}/">
<include name="${lib.dir}/*.jar" />
</fileset>
</path>
<target name="setUp">
<mkdir dir="${classes.dir}" />
<javac srcdir="${src.dir}" includeantruntime="false" destdir="${classes.dir}" classpathref="classpath"/>
</target>
<target name="compile" depends="setUp">
<local name="jar" />
<property name="jar" location="${target.dir}/gprd-logs-cleaner.jar" />
<spring-boot:exejar destfile="${jar}" classes="${classes.dir}">
<resources>
<fileset dir="${resource.dir}" />
</resources>
<lib>
<path refid="classpath" />
</lib>
</spring-boot:exejar>
</target>

<target name="clean">
<delete dir="${target.dir}" />
</target>

<!-- Default, run this -->
<target name="main" depends="clean, compile" />

</project>

Spring Boot版本:2.3.4.REASE.

我使用SpringBootAndlib版本进行了测试:spring-bot-antlib-2.4.jarspring-bot-atlib-2.4.0.jar,错误相同。

库列表:

spring-boot-starter-2.3.4.RELEASE.jar               istack-commons-runtime-3.0.11.jar
spring-boot-2.3.4.RELEASE.jar                       jakarta.activation-1.2.2.jar
spring-boot-autoconfigure-2.3.4.RELEASE.jar         spring-data-jpa-2.3.4.RELEASE.jar
spring-boot-starter-logging-2.3.4.RELEASE.jar       spring-data-commons-2.3.4.RELEASE.jar
logback-classic-1.2.3.jar                           spring-orm-5.2.9.RELEASE.jar
logback-core-1.2.3.jar                              slf4j-api-1.7.28.jar
log4j-to-slf4j-2.13.3.jar                           spring-aspects-5.2.9.RELEASE.jar
log4j-api-2.13.3.jar                                hibernate-entitymanager-5.4.5.Final.jar
jul-to-slf4j-1.7.28.jar                             jboss-logging-3.4.1.Final.jar
jakarta.annotation-api-1.3.5.jar                    dom4j-2.1.1.jar
spring-core-5.2.9.RELEASE.jar                       hibernate-commons-annotations-5.1.0.Final.jar
spring-jcl-5.2.9.RELEASE.jar                        javax.persistence-api-2.2.jar
snakeyaml-1.26.jar                                  byte-buddy-1.10.14.jar
spring-boot-starter-data-jpa-2.3.4.RELEASE.jar      jboss-transaction-api_1.2_spec-1.1.1.Final.jar
spring-boot-starter-aop-2.3.4.RELEASE.jar           spring-batch-core-4.2.4.RELEASE.jar
aspectjweaver-1.9.6.jar                             jackson-databind-2.11.2.jar
spring-boot-starter-jdbc-2.3.4.RELEASE.jar          jackson-annotations-2.11.2.jar
HikariCP-3.4.5.jar                                  jackson-core-2.11.2.jar
jakarta.transaction-api-1.3.3.jar                   micrometer-core-1.5.5.jar
jakarta.persistence-api-2.2.3.jar                   HdrHistogram-2.1.12.jar
hibernate-core-5.4.5.Final.jar                      LatencyUtils-2.0.3.jar
javassist-3.24.0-GA.jar                             javax.batch-api-1.0.jar
antlr-2.7.7.jar                                     jettison-1.2.jar
jandex-2.0.5.Final.jar                              spring-batch-infrastructure-4.2.4.RELEASE.jar
classmate-1.5.1.jar                                 spring-retry-1.2.5.RELEASE.jar
jaxb-runtime-2.3.3.jar                              spring-aop-5.2.9.RELEASE.jar
txw2-2.3.3.jar                                      spring-beans-5.2.9.RELEASE.jar
spring-context-5.2.9.RELEASE.jar                    spring-expression-5.2.9.RELEASE.jar
spring-tx-5.2.9.RELEASE.jar                         spring-jdbc-5.2.9.RELEASE.jar
jakarta.xml.bind-api-2.3.3.jar                      jakarta.activation-api-1.2.2.jar
jasypt-spring-boot-starter-2.0.0.jar                jasypt-spring-boot-2.0.0.jar
jasypt-1.9.2.jar

注意:我们无法连接到下载依赖项。提前感谢

java.lang.NoClassDefFoundError:org/springframework/util/StringUtils">

此错误表示找不到类org.springframework.util.StringUtils。此类位于spring-core模块中。

您共享的列表中有spring-core-5.2.9.RELEASE.jar,但它似乎不在类路径中。您需要确保这个jar在您的类路径中。

好的,我已经解决了这个问题。它已经完全编译好了,但还有一些调整要做。首先,您必须通过使用ant -debug -lib ./ext-lib/ -lib. /lib/运行命令来指示库的位置。我已经从spring-boot-antlib-jar中提取了xml的一部分,并根据我的需要进行了调整。我把你留在这里,以防对别人有用。

build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="gprd-logs-cleaner" default="main" basedir=".">
<property name="src.dir" location="src/main/java" />
<property name="resource.dir" location="src/main/resources" />
<property name="target.dir" location="target" />
<property name="classes.dir" location="${target.dir}/classes" />
<property name="lib.dir" value="lib" />
<property name="main-class" value="com.cleaner.App" />
<property name="spring-boot.version" value="2.3.4.RELEASE" />

<target name="init">
<mkdir dir="${build.dir}" />
</target>
<path id="classpath">
<fileset dir="${basedir}/">
<include name="${lib.dir}/*.jar" />
</fileset>
</path>
<!-- Need classpath to run this -->
<target name="compile" depends="init" description="compile the source ">
<javac includeantruntime="false" srcdir="${src.dir}"
destdir="${build.dir}" classpathref="classpath" />
</target>

<macrodef name="check-exejar" description="Create a spring-boot executable jar">
<attribute name="destfile" />
<attribute name="classes" />
<attribute name="start-class" default="" />
<attribute name="spring-boot-loader"/>
<element name="resources" optional="true"
description="includes resource collections specifying additional Java resources" />
<element name="lib" optional="true"
description="includes resource collections containing (jar) dependencies" />
<sequential>
<local name="start-class" />
<echo>Using start class @{start-class}</echo>
<local name="spring-boot.version" />
<local name="destdir" />
<dirname file="@{destfile}" property="destdir" />
<echo>Using destination directory ${destdir}</echo>
<mkdir dir="${destdir}/dependency" />
<echo>Extracting spring-boot-loader to ${destdir}/dependency</echo>
<local name="spring-boot.loader"/>

<copy todir="${destdir}/dependency">
<javaresource name="META-INF/loader/spring-boot-loader.jar">
<classpath location="@{spring-boot-loader}"/>
</javaresource>
<flattenmapper />
</copy>
<echo>Embedding spring-boot-loader v2.4.4...</echo>
<jar destfile="@{destfile}" compress="false">
<mappedresources>
<fileset dir="@{classes}"/>
<globmapper from="*" to="BOOT-INF/classes/*" />
</mappedresources>
<resources />
<mappedresources>
<lib />
<globmapper from="*" to="BOOT-INF/lib/*" />
</mappedresources>
<zipfileset src="${destdir}/dependency/spring-boot-loader.jar" />
<manifest>
<attribute name="Main-Class"
value="com.cleaner.App" />
<attribute name="Start-Class" value="org.springframework.boot.loader.PropertiesLauncher" />
<attribute name="Implementation-Title" value="gprd-logs-cleaner"/>
<attribute name="Spring-Boot-Classes" value="BOOT-INF/classes/" />
<attribute name="Spring-Boot-Lib" value="BOOT-INF/lib/" />
</manifest>
</jar>
</sequential>
</macrodef>

<target name="build" >
<local name="jar" />
<property name="jar" location="${target.dir}/gprd-logs-cleaner.jar" />
<property name="spring-boot.loader" location="${basedir}/ext-lib/spring-boot-loader-tools-2.4.4.jar" />
<check-exejar destfile="${jar}" classes="${classes.dir}" spring-boot-loader="${spring-boot.loader}" 
start-class="com.cleaner.App">
<resources>
<fileset dir="${resource.dir}" />
</resources>
<lib>
<path refid="classpath" />
</lib>
</check-exejar>
</target>

<!-- Default, run this -->
<target name="main" depends="build"/>
</project>

我使用属性Luncher,因为我必须从最终的罐子中提取属性

相关内容

  • 没有找到相关文章

最新更新