如何将 .java 文件转换为 .class 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3398314/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to convert a .java file to a .class file?
提问by plr
I am new to Java. I was given some .java
files and was told if I could convert them, then I could use them. It is for a game bot I am using. They changed to a new API which I don't understand, so the bot won't run unless it is implemented in .class
files.
我是 Java 新手。我得到了一些.java
文件,并被告知是否可以转换它们,然后我就可以使用它们。它适用于我正在使用的游戏机器人。他们改用了我不理解的新 API,因此除非在.class
文件中实现,否则机器人不会运行。
Can someone explain me how to convert these .java
files to fully functional .class
files?
有人可以解释我如何将这些.java
文件转换为功能齐全的.class
文件吗?
回答by polygenelubricants
You need to compile the .java
source code to the .class
byte code. Use a Java compiler like javac
from Sun's JDK, or if you're using an IDE like Eclipse, it already has a compiler that can generate the .class
files for you (usually in the \bin
directory).
您需要将.java
源代码编译为.class
字节码。使用javac
来自 Sun 的 JDK 之类的 Java 编译器,或者如果您使用的是 Eclipse 之类的 IDE,它已经有一个可以.class
为您生成文件的编译器(通常在\bin
目录中)。
See also
也可以看看
Related links for javac
相关链接 javac
回答by speshak
You need to compile the java using javac (the java compiler) You can get it as part of the JDK which you can get from Oracle (http://www.oracle.com/technetwork/java/javase/downloads/index.html)
您需要使用 javac(java 编译器)编译 java 您可以将它作为 JDK 的一部分,您可以从 Oracle ( http://www.oracle.com/technetwork/java/javase/downloads/index.html)
You'll need to run a command like the following
您需要运行如下命令
javac foo.java
Which will produce a corresponding foo.class
这将产生一个相应的 foo.class
回答by KARTHIKEYAN.A
if you want to compile multiple java files into class files then you follow given procedure.
如果要将多个 java 文件编译为类文件,请按照给定的程序进行操作。
Syntex:
语法:
javac <options> <source files>
Example:
例子:
javac -cp -d classfolder *.java
here
这里
options are -cp (copy), -d (directory), classfolder (directory name)
source files are * (all) .java files