简体   繁体   English

在 Eclipse 上运行的 Java 项目,但在使用批处理时出错

[英]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.

相关问题 在Eclipse上运行项目时出错 - error while running project on eclipse 在Eclipse IDE中运行Java Maven项目时出现编译错误 - Getting an compillation error while running java maven project in the eclipse IDE 使用eclipse,java maven项目可以编译,但是在运行时会给出错误 - using eclipse, java maven project compiles but gives error when running Eclipse 构建项目时出错 - java.lang.IllegalArgumentException: Malformed \uxxxx encoding - Eclipse giving error while building project - java.lang.IllegalArgumentException: Malformed \uxxxx encoding 在Eclipse Kepler中运行插件项目时出现“ Java™Platform SE二进制文件已停止工作”错误 - “Java(TM) Platform SE binary has stopped working” error while running a plugin project in Eclipse Kepler 在 eclipse 运行时错误中运行 android 项目时出错 - Error while running the android project in eclipse run time error 使用批处理文件运行Java项目(在eclipse中内置) - Run Java project (built in eclipse) using Batch File 通过Vmware在Cloudera中的Eclipse上使用Spark和Java创建Wordcount项目时出错 - Error while creating Wordcount project using Spark & Java on Eclipse in Cloudera through Vmware Eclipse 4.9在使用Java 10 var关键字时出现编译错误 - eclipse 4.9 giving compilation error on using java 10 var keyword 使用Java(Eclipse)时出现SQL语法错误 - SQL syntax error, while using java(eclipse)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM