【发布时间】:2014-07-19 14:39:42
【问题描述】:
我已经在这些战壕中战斗了一段时间,但还没有完成这项工作。在 SO 上使用许多示例以及 this blog 或 this SO post 等其他示例,我仍然无法超过 Windows 类路径限制。我目前正在处理一个 ant 任务,该任务在我的源代码中的 java 类中运行单个 main 方法。如果我可以在这里工作,我可以在其他地方进行推断。
首先,我原来的相关构建任务
<path id="code.classpath">
<path id="code.classpath">
<path refid="jars.code"/>
<path refid="jars.common"/>
<path refid="jars.servlet-api"/>
<dirset dir="${code.dir}" excludes="xlib/scripts/**"/>
</path>
<target name="code.exec" description="Execute a class file">
<echo>${code}</echo>
<input addproperty="code.exec.class">Enter full class name (e.g. ${atmr.pkg}.FooBar):</input>
<input addproperty="code.exec.args">Enter arguments:</input>
<java classname="${code.exec.class}"
fork="true"
dir="${code.src.dir}"
failonerror="true"
classpathref="code.classpath">
<jvmarg value="-Xmx4048M"/>
<jvmarg value="-ea"/>
<jvmarg value="-Dlog4j.configuration=file:${basedir}/log4j.xml"/>
<syspropertyset refid="proxy.properties"/>
<assertions refid="code.exec.assertions"/>
<arg line="${code.exec.args}"/>
</java>
</target>
接下来,我最近尝试的解决方案
<path id="code.source">
<dirset dir="${code.dir}" excludes="xlib/scripts/**"/>
</path>
<target name="code.classpath.acme">
<manifestclasspath property="jar.classpath" jarfile="${app.dir}/acme.jar">
<classpath refid="code.source"/>
</manifestclasspath>
<jar destfile="${app.dir}/acme.jar" index="true">
<manifest>
<attribute name="Class-Path" value="${jar.classpath}"/>
</manifest>
</jar>
</target>
<path id="temp.classpath">
<pathelement path="${app.dir}/acme.jar"/>
</path>
<target name="code.exec" description="Execute a class file" >
<property name="myclasspath" refid="temp.classpath"/>
<echo>${code}</echo>
<echo>${basedir}</echo>
<echo>${myclasspath}</echo>
<input addproperty="code.exec.class">Enter full class name (e.g. ${atmr.pkg}.FooBar):</input>
<input addproperty="code.exec.args">Enter arguments:</input>
<java classname="${code.exec.class}"
fork="true"
dir="${code.src.dir}"
failonerror="true"
classpathref="temp.classpath">
<jvmarg value="-Xmx4048M"/>
<jvmarg value="-ea"/>
<jvmarg value="-Dlog4j.configuration=file:${basedir}/log4j.xml"/>
<syspropertyset refid="proxy.properties"/>
<assertions refid="code.exec.assertions"/>
<arg line="${code.exec.args}"/>
</java>
</target>
基本上,在运行第一个时,我在 Windows 中遇到“类路径太长”的问题。运行第二个,我得到“无法找到或加载主类 package.classname”。我已经浏览了在 jar 中创建的 MANIFEST.MF 并且存在包位置。从这里开始,我沿着兔子洞旅行,寻找可能发生的事情。我已经测试了清单相对位置的不同排列,但无济于事。我什至已经进入并手动将清单更改为显式文件位置(与 jar 无关),结果没有任何变化。
为了确认整个代码有效,我可以将我的 code.dir 路径添加到 temp.classpath 并得到太长的错误。我还可以使用其中的类构建 acme jar,并解决缺少类的问题。
在我阅读的任何地方,这都应该有效。然而,我在这里。我知道如果清单中的引用找不到,它会默默地跳过它。这就是它似乎正在做的事情,但我已经尝试了一切来让它看看有什么无济于事。因此,我求助 SO 贡献者,要么指出我错过的愚蠢错误,要么让我了解我尚未学习的秘密知识。
提前致谢。
【问题讨论】:
标签: java ant jar classpath manifest