javac 不产生输出
我正在尝试使用 javac 从命令行编译 java 项目,但在命令行上没有得到任何输出。此外,不会生成 .class 文件。
我用来调用 javac 命令的确切语法如下:
javac @options @javaFiles
选项文件的内容如下:
-g
-verbose
-d classes
-classpath cp1;cp2;cp3
其中 cp1、2、3 等引用我的计算机上的 jar 文件。 javaFiles 文件包含我希望编译的 java 文件列表:
C:\path\to\dir\one.java
C:\path\to\dir\two.java
问题是命令行上没有输出(如果我拼写错误了命令行开关之一,那么命令行上会出现错误输出)并且类文件夹中不会生成 .class 文件。 另外,如果我将“-Xstdout output.txt”开关添加到选项文件中并尝试编译。 javac 命令退出并创建 output.txt 文件,但文件中没有信息。
我的问题是: 我是否使用了错误的语法来调用 javac?我应该如何更改它?
编辑:
我更改了 Jasper 的答案中提到的选项和 javaFiles 文件,但我得到了 现在出现以下错误:
*__* javac @options @javaFiles
javac:找不到文件:com\compname\cloud\automation\portal\definitions\landing\LandingPage.java
用法:javac <选项> <源文件>
使用 -help 获取可能选项的列表
编辑 2:
好的,这个问题与类路径上的 jar 之一有关。当该 jar 被删除时(一次删除每个 jar 的痛苦),一切都会正确编译并创建 .class 文件。
我仍然不确定为什么当这个 jar 位于类路径上时 javac 会默默地失败,即使使用了详细开关。
目前,我可以不使用这个罐子。我感谢人们提供的帮助......
I am trying to compile a java project from the command line using javac but I am getting no output on the command line. Also, the .class files are not being generated.
The exact syntax I am using to invoke the javac command is below:
javac @options @javaFiles
The contents of the options file is below:
-g
-verbose
-d classes
-classpath cp1;cp2;cp3
where cp1, 2, 3 etc refer to jar files on my machine. The javaFiles file has a list of java files that I wish to compile:
C:\path\to\dir\one.java
C:\path\to\dir\two.java
The problem is that there is no output on the command line (If I miss-spell one of the command line switches then there is error output on the command line) and no .class files are generated in the classes folder.
Also, if I add the '-Xstdout output.txt' switch to the options files and try and compile. The javac command, exits and the output.txt fiel is created but there is no information in the file.
My question, is:
Am I using the wrong syntax to invoke javac and how should I change this?
EDIT:
I changed the options and javaFiles files as mentioned in Jasper's answer, but am getting the
below error now:
*__* javac @options @javaFiles
javac: file not found: com\compname\cloud\automation\portal\definitions\landing\LandingPage.java
Usage:javac <options> <source files>
use -help for a list of possible options
EDIT 2:
Ok, this issue was with one of the jars on the classpath. When that jar was removed (pain in the a$$ removing each jar at a time) everything compiles correctly and the .class files are created.
I'm still not sure why javac fails silently when this jar is on the classpath, even with the verbose switch being used.
For the moment, I can get around not using this jar. I appreciate the help people have provided...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在第二个文件中,不使用完整路径名,而是仅使用包基目录中的路径名。假设您的代码位于包
org.mypackage
中,并且源文件位于目录C:\myproject\src\org\mypackage
中,请将其放入第二个文件中:在第一个文件中,添加
-sourcepath
选项:In the second file, instead of using full pathnames, use only the pathnames from the base directory of the package. Suppose your code is in a package
org.mypackage
, and your source files are in the directoryC:\myproject\src\org\mypackage
, put this in the second file:In the first file, add a
-sourcepath
option:我刚刚遇到了同样的问题,它似乎与签名与未签名的第三方 jar 文件有关:
希望这有帮助,
.安德里亚
I just ran into the same problem, and it seems related to signed vs. unsigned third-party jar files:
Hope this helps,
.Andrea