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:
我尝试在Windows XP命令行上手动运行一个特定的JUnit测试,它在类路径中有非常多的元素。我试过几种不同的方法,比如:
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
(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:
(其他变体则将类路径全部设置在一行上,将类路径通过-类路径设置为java的参数)。它总是会出现在控制台,抛出它的手和这个错误:
The input line is too long.
The syntax of the command is incorrect.
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!
这是一个JUnit测试,测试了一个相当大的现有遗留项目,所以没有建议将我的目录结构重新安排到更合理的地方,这些类型的解决方案现在已经过时了。我只是想对这个项目进行快速测试,然后在命令行上运行它,控制台正在妨碍我。的帮助!
9 个解决方案
#1
49
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.
在这方面,Windows命令行非常有限。一个变通方法是创建一个“pathing jar”。这是一个只包含一个清单的罐子。mf文件,它的类路径指定了长列表的jar文件的磁盘路径,等等。现在,只需将这个pathing jar添加到命令行类路径中。这通常比将实际资源打包在一起更方便。
As I recall, the disk paths can be relative to the pathing jar itself. So the Manifest.mf
might look something like this:
我记得,磁盘路径可以相对于pathing jar本身。所以清单。mf可能是这样的:
Class-Path: this.jar that.jar ../lib/other.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:
如果您的pathing jar包含主要的基础资源,那么它不会太频繁地发生变化,但是您可能仍然希望在构建的某个地方生成它。例如:
<jar destfile="pathing.jar">
<manifest>
<attribute name="Class-Path" value="this.jar that.jar ../lib/other.jar"/>
</manifest>
</jar>
#2
17
Since Java 6 you can use classpath wildcards.
因为Java 6可以使用类路径通配符。
Example: foo/*
, refers to all .jar files in the directory foo
示例:foo/*,是指目录foo中的所有.jar文件。
- this will not match class files (only jar files). To match both use:
foo;foo/*
orfoo/*;foo
. The order determines what is loaded first. - 这将不匹配类文件(只有jar文件)。匹配两个使用:foo;foo/*或foo/*;foo。顺序决定先装入什么。
- The search is NOT recursive
- 搜索不是递归的。
#3
4
(I suppose you do not really mean DOS, but refer to cmd.exe.)
(我认为你并不是指DOS,而是指cmd.exe。)
I think it is less a CLASSPATH limitation than an environment size/environment variable size limit. On XP, individual environment variables can be 8k in size, the entire environment is limited to 64k. I can't see you would hit that limit.
我认为它不是一个类路径限制,而是一个环境大小/环境变量的大小限制。在XP中,单个环境变量的大小可以为8k,整个环境限制为64k。我看不出你会达到这个极限。
There is a limit on windows that restricts the length of a command line, on WindowsNT+ it is 8k for cmd.exe. A set command is subject to that restriction. Can it be you have more than 8k worth of directories in your set command? You may be out of luck, then - even if you split them up like Nick Berardi suggested.
在WindowsNT+上,限制命令行长度的窗口有一个限制,它是cmd.exe的8k。设置命令受此限制。您是否可以在您的set命令中拥有超过8k的目录?你可能运气不好,即使你把他们分开,就像尼克·贝拉尔迪建议的那样。
#4
1
If I were in your shoes, I would download the junction utility from MS : http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx and then map your "C:\path" to say, "z:\" and "c:\path2" to say, "y:\". This way, you will be reducing 4 characters per item in your classpath
.
如果我在你的位置,我会从MS: http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx下载连接实用程序,然后将你的“C:\path”映射为“z:\”和“C:\ path2”,然后说:“y:\”。这样,您将在类路径中减少4个字符。
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;
Now, your classpath will be :
现在,您的类路径将是:
set CLASS_PATH=z\a\b\c;z\e\f\g;
set CLASS_PATH=%CLASS_PATH%;y:\a\b\c;y:\e\f\g;
It might do more depending on your actual classpath
.
它可能会更依赖于您实际的类路径。
#5
0
I think you are up the creek without a paddle here. The commandline has a limit for arguments to call a programm.
我想你在这条小溪上没有桨。命令行有一个称为程序的参数的限制。
I have 2 sugestion you could try. First, prior to running the junit tests, you can let a script/ant_task create JARs of the various classes on the classpath. Then you can put the JARs on the classpath, which should be shorter.
我有两个建议,你可以试一试。首先,在运行junit测试之前,您可以让一个脚本/ant_task在类路径上创建各种类的jar。然后,您可以将jar放到类路径中,它应该更短。
Another way you could try is to create an antscript to run JUNIT, in ANT there should not be such a limit for classpath entries.
另一种方法是创建一个用于运行JUNIT的antscript,在ANT中不应该对类路径条目有这样的限制。
#6
0
As HuibertGill mentions, I would wrap this in an Ant build script just so that you don't have to manage all of this yourself.
正如HuibertGill提到的那样,我将用Ant构建脚本将其包装起来,这样您就不必自己管理所有这些了。
#7
0
You could try this
你可以试试这个
@echo off
set A=D:\jdk1.6.0_23\bin
set B=C:\Documents and Settings\674205\Desktop\JavaProj
set PATH="%PATH%;%A%;"
set CLASSPATH="%CLASSPATH%;%B%;"
go to a command prompt and run it twice(no idea why....i have to do so on a windows XP machine) also the paths r set only for the current command prompt session
打开命令提示符并运行它两次(不知道为什么....我必须在windows XP机器上这样做),也只有在当前命令提示会话中设置的路径r。
#8
0
There was no solution to the issue other than somehow making the classpath shorter by moving the jar files into a folder like "C:\jars".
除了通过将jar文件移动到像“C:\jars”这样的文件夹之外,还没有办法解决这个问题。
#9
-2
Have you tried stacking them?
你试过把它们叠起来吗?
set CLASS_PATH = c:\path
set ALT_A = %CLASS_PATH%\a\b\c;
set ALT_B = %CLASS_PATH%\e\f\g;
...
set ALL_PATHS = %CLASS_PATH%;%ALT_A%;%ALT_B%
#1
49
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.
在这方面,Windows命令行非常有限。一个变通方法是创建一个“pathing jar”。这是一个只包含一个清单的罐子。mf文件,它的类路径指定了长列表的jar文件的磁盘路径,等等。现在,只需将这个pathing jar添加到命令行类路径中。这通常比将实际资源打包在一起更方便。
As I recall, the disk paths can be relative to the pathing jar itself. So the Manifest.mf
might look something like this:
我记得,磁盘路径可以相对于pathing jar本身。所以清单。mf可能是这样的:
Class-Path: this.jar that.jar ../lib/other.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:
如果您的pathing jar包含主要的基础资源,那么它不会太频繁地发生变化,但是您可能仍然希望在构建的某个地方生成它。例如:
<jar destfile="pathing.jar">
<manifest>
<attribute name="Class-Path" value="this.jar that.jar ../lib/other.jar"/>
</manifest>
</jar>
#2
17
Since Java 6 you can use classpath wildcards.
因为Java 6可以使用类路径通配符。
Example: foo/*
, refers to all .jar files in the directory foo
示例:foo/*,是指目录foo中的所有.jar文件。
- this will not match class files (only jar files). To match both use:
foo;foo/*
orfoo/*;foo
. The order determines what is loaded first. - 这将不匹配类文件(只有jar文件)。匹配两个使用:foo;foo/*或foo/*;foo。顺序决定先装入什么。
- The search is NOT recursive
- 搜索不是递归的。
#3
4
(I suppose you do not really mean DOS, but refer to cmd.exe.)
(我认为你并不是指DOS,而是指cmd.exe。)
I think it is less a CLASSPATH limitation than an environment size/environment variable size limit. On XP, individual environment variables can be 8k in size, the entire environment is limited to 64k. I can't see you would hit that limit.
我认为它不是一个类路径限制,而是一个环境大小/环境变量的大小限制。在XP中,单个环境变量的大小可以为8k,整个环境限制为64k。我看不出你会达到这个极限。
There is a limit on windows that restricts the length of a command line, on WindowsNT+ it is 8k for cmd.exe. A set command is subject to that restriction. Can it be you have more than 8k worth of directories in your set command? You may be out of luck, then - even if you split them up like Nick Berardi suggested.
在WindowsNT+上,限制命令行长度的窗口有一个限制,它是cmd.exe的8k。设置命令受此限制。您是否可以在您的set命令中拥有超过8k的目录?你可能运气不好,即使你把他们分开,就像尼克·贝拉尔迪建议的那样。
#4
1
If I were in your shoes, I would download the junction utility from MS : http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx and then map your "C:\path" to say, "z:\" and "c:\path2" to say, "y:\". This way, you will be reducing 4 characters per item in your classpath
.
如果我在你的位置,我会从MS: http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx下载连接实用程序,然后将你的“C:\path”映射为“z:\”和“C:\ path2”,然后说:“y:\”。这样,您将在类路径中减少4个字符。
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;
Now, your classpath will be :
现在,您的类路径将是:
set CLASS_PATH=z\a\b\c;z\e\f\g;
set CLASS_PATH=%CLASS_PATH%;y:\a\b\c;y:\e\f\g;
It might do more depending on your actual classpath
.
它可能会更依赖于您实际的类路径。
#5
0
I think you are up the creek without a paddle here. The commandline has a limit for arguments to call a programm.
我想你在这条小溪上没有桨。命令行有一个称为程序的参数的限制。
I have 2 sugestion you could try. First, prior to running the junit tests, you can let a script/ant_task create JARs of the various classes on the classpath. Then you can put the JARs on the classpath, which should be shorter.
我有两个建议,你可以试一试。首先,在运行junit测试之前,您可以让一个脚本/ant_task在类路径上创建各种类的jar。然后,您可以将jar放到类路径中,它应该更短。
Another way you could try is to create an antscript to run JUNIT, in ANT there should not be such a limit for classpath entries.
另一种方法是创建一个用于运行JUNIT的antscript,在ANT中不应该对类路径条目有这样的限制。
#6
0
As HuibertGill mentions, I would wrap this in an Ant build script just so that you don't have to manage all of this yourself.
正如HuibertGill提到的那样,我将用Ant构建脚本将其包装起来,这样您就不必自己管理所有这些了。
#7
0
You could try this
你可以试试这个
@echo off
set A=D:\jdk1.6.0_23\bin
set B=C:\Documents and Settings\674205\Desktop\JavaProj
set PATH="%PATH%;%A%;"
set CLASSPATH="%CLASSPATH%;%B%;"
go to a command prompt and run it twice(no idea why....i have to do so on a windows XP machine) also the paths r set only for the current command prompt session
打开命令提示符并运行它两次(不知道为什么....我必须在windows XP机器上这样做),也只有在当前命令提示会话中设置的路径r。
#8
0
There was no solution to the issue other than somehow making the classpath shorter by moving the jar files into a folder like "C:\jars".
除了通过将jar文件移动到像“C:\jars”这样的文件夹之外,还没有办法解决这个问题。
#9
-2
Have you tried stacking them?
你试过把它们叠起来吗?
set CLASS_PATH = c:\path
set ALT_A = %CLASS_PATH%\a\b\c;
set ALT_B = %CLASS_PATH%\e\f\g;
...
set ALL_PATHS = %CLASS_PATH%;%ALT_A%;%ALT_B%