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

查看:100
本文介绍了如何在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:\path\a\b\c;C:\path\e\f\g;....
set CLASS_PATH=%CLASS_PATH%;C:\path2\a\b\c;C:\path2\e\f\g;....
...
C:\apps\jdk1.6.0_07\bin\java.exe -client oracle.jdevimpl.junit.runner.TestRunner com.myco.myClass.MyTest testMethod

(其他变体正在设置classpath全部在一行上,通过-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测试,因此没有关于将我的目录结构重新安排到更合理的建议的建议,那些类型的解决方案现在已经出来。我只是tr为了对这个项目进行快速测试并在命令行上运行它,控制台正在阻止我。帮助!

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 添加到命令行类路径中。这通常比将实际资源打包在一起更方便。

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

如果你的 pathing 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天全站免登陆