如何在 Windows 中设置长的 Java 类路径? [英] How to set a long Java classpath in Windows?

查看:17
本文介绍了如何在 Windows 中设置长的 Java 类路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Windows XP 命令行上手动运行特定的 JUnit 测试,该命令行在类路径中具有异常多的元素.我尝试了几种变体,例如:

I'm trying to run a particular JUnit test by hand on a Windows XP command line, which has an unusually high number of elements in the class path. I've tried several variations, such as:

set CLASS_PATH=C:pathac;C:pathefg;....
set CLASS_PATH=%CLASS_PATH%;C:path2ac;C:path2efg;....
...
C:appsjdk1.6.0_07injava.exe -client oracle.jdevimpl.junit.runner.TestRunner com.myco.myClass.MyTest testMethod

(其他变体是在一行上设置类路径,通过 -classpath 将类路径设置为 java 的参数").它总是归结为控制台抛出这个错误:

(Other variations are setting the classpath all on one line, setting the classpath via -classpath as an argument to java"). It always comes down to the console throwing up it's hands with this error:

The input line is too long.
The syntax of the command is incorrect.

这是一个 JUnit 测试,测试一个相当大的现有遗留项目,所以没有关于将我的目录结构重新安排为更合理的建议,这些类型的解决方案现在已经出来了.我只是想针对这个项目生成一个快速测试并在命令行上运行它,而控制台正在阻碍我.帮助!

This is a JUnit test testing a rather large existing legacy project, so no suggestions about rearranging my directory structure to something more reasonable, those types of solutions are out for now. I was just trying to gen up a quick test against this project and run it on the command line, and the console is stonewalling me. Help!

推荐答案

Windows 命令行在这方面非常有限.一种解决方法是创建一个路径 jar".这是一个仅包含 Manifest.mf 文件的 jar,其 Class-Path 指定了长长的 jar 列表等的磁盘路径.现在只需添加这个 路径 jar 到您的命令行类路径.这通常比将实际资源打包在一起更方便.

The Windows command line is very limiting in this regard. A workaround is to create a "pathing jar". This is a jar containing only a Manifest.mf file, whose Class-Path specifies the disk paths of your long list of jars, etc. Now just add this pathing jar to your command line classpath. This is usually more convenient than packaging the actual resources together.

我记得,磁盘路径可以相对于路径 jar 本身.所以 Manifest.mf 可能看起来像这样:

As I recall, the disk paths can be relative to the pathing jar itself. So the Manifest.mf might look something like this:

Class-Path: this.jar that.jar ../lib/other.jar

如果您的路径 jar 主要包含基础资源,那么它不会更改太频繁,但您可能仍然希望在构建中的某个地方生成它.例如:

If your pathing jar contains mainly foundational resources, then it won't change too frequently, but you will probably still want to generate it somewhere in your build. For example:

<jar destfile="pathing.jar">
  <manifest>
    <attribute name="Class-Path" value="this.jar that.jar ../lib/other.jar"/>
  </manifest>
</jar>

这篇关于如何在 Windows 中设置长的 Java 类路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆