Java 已弃用的编译错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16239215/
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-16 05:57:25  来源:igfitidea点击:

Deprecated compiling error

javacompilationjavacdeprecated

提问by hunterge

I'm trying to compile my Java program, however I am getting a "Deprecated File" error.

我正在尝试编译我的 Java 程序,但是我收到了“已弃用的文件”错误。

I normally compile the file by typing "Javac FileName.java", however I get an error saying:

我通常通过键入“Javac FileName.java”来编译文件,但是我收到一条错误消息:

FileName.java uses or overrides a depreacted API. Recompile with Xlint-deprecation for details.

FileName.java 使用或覆盖已弃用的 API。有关详细信息,请使用 Xlint-deprecation 重新编译。

What do I type into the command line to make it run?

我在命令行中输入什么以使其运行?

回答by Jops

It's not an error, just a warning.

这不是错误,只是警告

The compiler will still produce a class file and you will be able to run it. However, it's a good idea to address the warning, since using deprecated API could lead to more problems later on.

编译器仍会生成一个类文件,您将能够运行它。但是,解决警告是个好主意,因为使用已弃用的 API 可能会导致以后出现更多问题。

If you choose to see the warnings, you can do this:

如果您选择查看警告,则可以执行以下操作:

javac -Xlint:deprecation FileName.java

回答by Aaron Lee

I was getting the same exception in running a gradlew build. I discovered that the path included Java 1.7 and my JAVA_HOME variable path had 1.8 specifed. Once I updated the path to 1.8, the build was successful.

我在运行 gradlew 构建时遇到了同样的异常。我发现该路径包含 Java 1.7,而我的 JAVA_HOME 变量路径指定了 1.8。一旦我将路径更新为 1.8,构建就成功了。

回答by Ayo Johnson

If you don't have a deprecation

如果你没有弃用

javac -Xlint Filename.java

回答by Life_nduwi

Had the similar issue and setting the PATH to the correct file that contains the JDK worked. For windows, search environnement variables > select edit environnement variables > Enter JAVA_HOME as variable and set the value to the jdk file.

有类似的问题,并将 PATH 设置为包含 JDK 的正确文件。对于windows,搜索环境变量>选择编辑环境变量>输入JAVA_HOME作为变量并将值设置为jdk文件。