如何在 Eclipse 中使用任何 javac 标志编译 Web 应用程序

How to compile web application with any javac flag in Eclipse

我有一个 Web 应用程序,我想在其中使用反射检索方法的参数名称 java.lang.reflect.Method.getParameters。但是,仅当 Java 文件使用 -parameters 标志编译时才能检索参数名称。

You can obtain the names of the formal parameters of any method or constructor with the method java.lang.reflect.Executable.getParameters. (The classes Method and Constructor extend the class Executable and therefore inherit the method Executable.getParameters.) However, .class files do not store formal parameter names by default. This is because many tools that produce and consume class files may not expect the larger static and dynamic footprint of .class files that contain parameter names. In particular, these tools would have to handle larger .class files, and the Java Virtual Machine (JVM) would use more memory. In addition, some parameter names, such as secret or password, may expose information about security-sensitive methods.

To store formal parameter names in a particular .class file, and thus enable the Reflection API to retrieve formal parameter names, compile the source file with the -parameters option to the javac compiler.

来源:https://docs.oracle.com/javase/tutorial/reflect/member/methodparameterreflection.html

如何指示 Eclipse 使用 -parameters 编译我的 Web 应用程序,以便稍后可以使用使用 -parameters 编译的代码在 Eclipse 中启动 Tomcat 服务器?

Eclipse 有自己的 Java 编译器,可以在 Project > Properties: Java Compiler 中设置 -parameters 标志的等价物 通过勾选最后一个复选框:存储有关方法参数的信息(可通过反射使用)(这不是默认启用,需要 Java 8 或更高)。