gpt4 book ai didi

Java ANT : Issues with build. xml

转载 作者:行者123 更新时间:2023-12-01 15:20:54 28 4
gpt4 key购买 nike

我想知道是否有人可以帮助我解决一个严重的问题......我需要从使用大量依赖项的项目创建一个 jar...问题是:我亲手编写的 build.xml 文件无法正常工作。更具体地说,它运行没有任何问题,只是一个警告:

Buildfile: C:\Users\Alexis Fasquel\workspace\FirstEditServer\build.xml
clean:
[delete] Deleting directory C:\Users\Alexis Fasquel\workspace\FirstEditServer\bin
[delete] Deleting directory C:\Users\Alexis Fasquel\workspace\FirstEditServer\dist
makedir:
[mkdir] Created dir: C:\Users\Alexis Fasquel\workspace\FirstEditServer\bin
[mkdir] Created dir: C:\Users\Alexis Fasquel\workspace\FirstEditServer\dist
compile:
[javac] C:\Users\Alexis Fasquel\workspace\FirstEditServer\build.xml:101: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 14 source files to C:\Users\Alexis Fasquel\workspace\FirstEditServer\bin
jar:
[jar] Building jar: C:\Users\Alexis Fasquel\workspace\FirstEditServer\dist\firstEditServer.jar
main:
BUILD SUCCESSFUL
Total time: 1 second

但不幸的是我仍然遇到一些 classNotFoundDefError

<小时/>

我没有打印完整的跟踪,因为这是我尝试实例化的第一个类,但没有找到......所以我猜什么都不起作用......但这是:

Exception in thread "main" java.lang.NoClassDefFoundError: gate/util/GateExcept
on
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: gate.util.GateException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more

这是我的 build.xml 文件...有人可以看一下它,也许可以找到我的错误是什么?

<?xml version="1.0"?>
<project name="Ant-Test" default="main" basedir=".">
<!-- Sets variables which can later be used. -->
<!-- The value of a property is accessed via ${} -->
<property name="src.dir" location="src" />
<property name="bin.dir" location="bin" />
<property name="gate.dir" location="gate" />
<property name="virtuoso.dir" location="virtuoso" />
<property name="recommendation.dir" location="recommendation" />
<property name="dist.dir" location="dist" />

<path id="bin.classpath">
<fileset dir="${virtuoso.dir}">
<include name="openrdf-sesame-2.6.5-onejar.jar" />
<include name="slf4j-api-1.5.0.jar" />
<include name="slf4j-jdk14-1.5.0.jar" />
<include name="virt_sesame2.jar" />
<include name="virtjdbc3.jar" />
</fileset>

<fileset dir="${gate.dir}">
<include name="plugins\Gazetteer_LKB\Gazetteer_LKB.jar" />
<include name="lib\gate.jar" />
<include name="lib\log4j.jar" />
<include name="lib\commons-io.jar" />
<include name="plugins\Tagger_Framework\TaggerFramework.jar" />
<include name="lib\ant-contrib.jar" />
<include name="lib\ant-launcher.jar" />
<include name="lib\ant.jar" />
<include name="lib\aopalliance.jar" />
<include name="lib\apache-mime4j-core.jar" />
<include name="lib\apache-mime4j-dom.jar" />
<include name="lib\bcmail-jdk15.jar" />
<include name="lib\bcprov-jdk15.jar" />
<include name="lib\commons-codec.jar" />
<include name="lib\commons-compress.jar" />
<include name="lib\commons-lang.jar" />
<include name="lib\commons-logging.jar" />
<include name="lib\dom4j.jar" />
<include name="lib\fontbox.jar" />
<include name="lib\gate-asm.jar" />
<include name="lib\gate-compiler-jdt.jar" />
<include name="lib\lucene-core.jar" />
<include name="lib\metadata-extractor.jar" />
<include name="lib\nekohtml.jar" />
<include name="lib\pdfbox.jar" />
<include name="lib\poi-ooxml-schemas.jar" />
<include name="lib\poi-ooxml.jar" />
<include name="lib\poi-scratchpad.jar" />
<include name="lib\poi.jar" />
<include name="lib\spring-aop.jar" />
<include name="lib\spring-beans.jar" />
<include name="lib\spring-core.jar" />
<include name="lib\tika-core.jar" />
<include name="lib\tika-parsers.jar" />
<include name="lib\wstx-lgpl.jar" />
<include name="lib\xercesImpl.jar" />
<include name="lib\xmlbeans.jar" />
<include name="lib\xmlunit.jar" />
<include name="lib\xpp3.jar" />
<include name="lib\xstream.jar" />
<include name="lib\ivy.jar" />
<include name="lib\java-getopt.jar" />
<include name="lib\java2html.jar" />
<include name="lib\javacc.jar" />
<include name="lib\jaxen.jar" />
<include name="lib\jdom.jar" />
<include name="lib\jempbox.jar" />
<include name="lib\junit.jar" />
<include name="plugins\Gazetteer_LKB\lib\commons-cli-1.1.jar" />
<include name="plugins\Gazetteer_LKB\lib\commons-collections-3.2.1.jar" />
<include name="plugins\Gazetteer_LKB\lib\commons-httpclient-3.1.jar" />
<include name="plugins\Gazetteer_LKB\lib\kim-api-3.0-RC5.jar" />
<include name="plugins\Gazetteer_LKB\lib\kim-util-3.0-RC5.jar" />
<include name="plugins\Gazetteer_LKB\lib\owlim-lite-4.3.jar" />
<include name="plugins\Gazetteer_LKB\lib\trove4j-2.0.2.jar" />
<include name="plugins\Gazetteer_LKB\lib\openrdf-sesame-2.6.3-onejar.jar" />
<include name="plugins\Gazetteer_LKB\lib\slf4j-api-1.5.11.jar" />
<include name="plugins\Gazetteer_LKB\lib\slf4j-log4j12-1.5.11.jar" />
</fileset>

<fileset dir="${recommendation.dir}">
<include name="simmetrics_jar_v1_6_2_d07_02_07.jar" />
</fileset>
</path>

<!-- Deletes the existing bin, docs and dist directory-->
<target name="clean">
<delete dir="${bin.dir}" />
<delete dir="${dist.dir}" />
</target>

<!-- Creates the bin and dist directory-->
<target name="makedir">
<mkdir dir="${bin.dir}" />
<mkdir dir="${dist.dir}" />
</target>

<!-- Compiles the java code (including the usage of library for JUnit -->
<target name="compile" depends="clean, makedir">
<javac srcdir="${src.dir}" destdir="${bin.dir}" classpathref="bin.classpath">
</javac>

</target>


<!--Creates the deployable jar file -->
<target name="jar" depends="compile">
<jar destfile="${dist.dir}\firstEditServer.jar" basedir="${bin.dir}">
<manifest>
<attribute name="Main-Class" value="com.firstedit.main.Main" />
</manifest>
</jar>
</target>

<target name="main" depends="compile, jar">
<description>Main target</description>
</target>

</project>

正如你所看到的,GateException确实在gate.jar中...

enter image description here

最佳答案

暂时假设它没有找到的类位于 jar 文件 lib\gate.jar 中,我想说的是,您正在从以下源构建 jar (firstEditServer.jar) 文件:您的项目仅此而已。为了执行该 jar,您还需要确保 lib... 目录中的所有 jar 文件也在类路径中。

现在,如果您想要构建一个包含库 jar 中的所有类的单个 jar 文件,那么您必须稍微不同地构建 jar 文件。您无法构建包含其他 jar 的可执行 jar(具有 Main-Class 属性的 jar)。标准类加载器不会在一个 jar 中查找其他 jar 文件。因此,您需要将库 jar 类扩展到最终的 jar 中。

Ant 使用如下内容提供对此的支持。 zipgroupfileset 是一项任务,它将获取 jar 文件列表,展开它们并将类本身包含到目标 jar 中。我过滤掉了 manifest.mf 和属性文件,这样它们就不会与我自己的文件(例如库 jar 中的 log4j.properties 文件)发生冲突。

这将创建一个包含所有 lib jar 的所有内容的 jar。 list 文件将发生冲突,最后看到的 list 文件获胜。

<jar destfile='${build.dir}/lib-jars.jar'>
<zipgroupfileset dir='${lib.dir}'>
<include name='**/*.jar'/>
</zipgroupfileset>
</jar>

此处使用单个 jar 的 zipfileset 可以过滤掉所需的一个 jar 中的任何内容。这将删除 MANIFEST.MF 文件,但也可能会删除带有附加排除标记的其他文件。

<jar destfile='${jar.file}' basedir='${classes.dir}'>
<zipfileset src='${build.dir}/lib-jars.jar'>
<exclude name="META-INF/MANIFEST.MF"/>
</zipfileset>
<manifest>
<attribute name="Built-By" value="${user.name}"/>
<attribute name="Main-Class" value="${main.class}"/>
<section name="common">
<attribute name="Specification-Title" value="${project.title}"/>
<attribute name="Specification-Version" value="${release.version}"/>
<attribute name="Specification-Vendor" value="${vendor}"/>
<attribute name="Implementation-Title" value="${project.title}"/>
<attribute name="Implementation-Version" value="${release.version} ${TODAY}"/>
<attribute name="Implementation-Vendor" value="${vendor}"/>
</section>
</manifest>
</jar>

关于Java ANT : Issues with build. xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10949181/

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