简体   繁体   English

尝试通过javac编译.java文件时遇到麻烦

[英]Trouble when trying to compile a .java file through javac

When trying to run the following command to compile some_file.java in Windows 尝试在Windows中运行以下命令来编译some_file.java

javac -classpath "some_class_path" "some_file.java"

it fails, telling me I didn't pass it any source files. 它失败,告诉我我没有传递任何源文件。

If instead I make 如果相反,我做

cd "some_class_path"
javac -classpath "some_class_path" "some_file.java"

it works fine. 它工作正常。 Why? 为什么? This bothers me as I want to compile a set of .java files from my program through javac . 这让我感到困扰,因为我想通过javac从程序中编译一组.java文件。

It would help if you could be more concrete about your description, but it looks like you're expecting the classpath to be used to look for the files you specify on the command-line as well. 如果您可以更具体地描述,这将有所帮助,但是看起来您希望类路径也可以用于在命令行中查找指定的文件。 It doesn't work that way - the source files you specify must be the exact paths to those files. 这样行不通-您指定的源文件必须是这些文件的确切路径。

Try to use full path to java source file. 尝试使用Java源文件的完整路径。 Anyway, could you provide exact commands and exceptions? 无论如何,您能否提供确切的命令和异常?

This is not the usage of the classpath. 这不是类路径的用法。 The classpath option specifies where to find the dependencies, not the source files. classpath选项指定在哪里找到依赖项,而不是源文件。 Just compile using: 只需使用以下命令进行编译:

javac "path\file"

(windows version) (Windows版本)

I don't think I see any obvious reason why that wouldn't work but then work if you're in that directory. 我认为我看不出有任何明显的原因为什么不起作用,但是如果您在该目录中就可以起作用。 Maybe quotes don't work the way I think they do in Windows. 也许引号并不像我认为的那样在Windows中起作用。 Either way, I suggest that you look at Ant , as it is the industry standard way to compile a set of java files. 无论哪种方式,我都建议您查看Ant ,因为它是编译一组Java文件的行业标准方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM