如何将 .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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 22:57:06  来源:igfitidea点击:

How to convert a .java file to a .class file?

java

提问by plr

I am new to Java. I was given some .javafiles 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 .classfiles.

我是 Java 新手。我得到了一些.java文件,并被告知是否可以转换它们,然后我就可以使用它们。它适用于我正在使用的游戏机器人。他们改用了我不理解的新 API,因此除非在.class文件中实现,否则机器人不会运行。

Can someone explain me how to convert these .javafiles to fully functional .classfiles?

有人可以解释我如何将这些.java文件转换为功能齐全的.class文件吗?

回答by polygenelubricants

You need to compile the .javasource code to the .classbyte code. Use a Java compiler like javacfrom Sun's JDK, or if you're using an IDE like Eclipse, it already has a compiler that can generate the .classfiles for you (usually in the \bindirectory).

您需要将.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