[英]Java project running on eclipse but giving error while using batch
I made a project for my uni.我为我的大学做了一个项目。 where I need to pass command line arguments.
我需要传递命令行参数的地方。 It is running perfectly fine on eclipse but when I run it using a batch file.
它在 eclipse 上运行得非常好,但是当我使用批处理文件运行它时。
my batch file looks like我的批处理文件看起来像
set path = "c:\Program Files\Java\jdk-14.0.2\bin";
javac FileHand.java
java FileHand DirectBuffer 1024 Sample.txt
pause
Do not set %path% at all.根本不要设置 %path%。 If you want to 'hardcode' the full path to java, then do so;
如果你想对java的完整路径进行“硬编码”,那么就这样做; write
C:\\program files\\....\\javac
, or SET JAVA_LOC=...
and then %JAVALOC%\\javac
.写入
C:\\program files\\....\\javac
,或SET JAVA_LOC=...
然后%JAVALOC%\\javac
。 But, this is clearly is not needed;但是,这显然是不需要的; you messed up your SET PATH statement and yet javac is being invoked, so, you should probably just remove the entire 'set path' line.
您弄乱了 SET PATH 语句,但正在调用 javac,因此,您可能应该删除整个“设置路径”行。
The problem is classpath.问题是类路径。 There is a file named DirectBuffer.class.
有一个名为 DirectBuffer.class 的文件。 It is somewhere - you said that 'it works in eclipse', which means eclipse can find this file, because you told it where it is.
它在某个地方——你说“它在 eclipse 中有效”,这意味着 eclipse 可以找到这个文件,因为你告诉它它在哪里。 You need to tell javac where it is.
你需要告诉 javac 它在哪里。 You do this as follows:
您可以按如下方式执行此操作:
javac -cp LOC1;LOC2;LOC3 FileHandjava
java -cp .;LOC1;LOC2;LOC3 FileHand DirectBuffer 1024 Sample.txt
where LOC1
is a path.其中
LOC1
是一条路径。 It can be a directory, or a jar file.它可以是一个目录,也可以是一个 jar 文件。 Your question does not make this clear, but let's say
DirectBuffer' is in the
com.foo.pkg package (so, you have
import com.foo.pkg.DirectBuffer;` in your source file), then:您的问题没有说明这一点,但假设
DirectBuffer' is in the
com.foo.pkg package (so, you have
的源文件中package (so, you have
import com.foo.pkg.DirectBuffer;`),然后:
either:任何一个:
cd (whatever you put for LOC1)
cd com\foo\pkg
dir
should print, amongst other things, 'DirectBuffer.class', or, if LOC1 is a jar file:应该打印,除其他外,'DirectBuffer.class',或者,如果 LOC1 是一个 jar 文件:
jar tvf (the jar file listed in LOC1)
should print com/foo/pkg/DirectBuffer.class
, amongst other things.应该打印
com/foo/pkg/DirectBuffer.class
等等。 You've already told eclipse this, so now find those places where you did that and tell javac about it.您已经告诉 eclipse 了,所以现在找到您执行该操作的地方并告诉 javac。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.