简体   繁体   English

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

[英]How to compile web application with any javac flag in Eclipse

I have a web application in which I want to retrieve method's parameter names with reflection java.lang.reflect.Method.getParameters .我有一个 Web 应用程序,我想在其中使用反射java.lang.reflect.Method.getParameters检索方法的参数名称。 Howerver parameter names can be retrieved only if Java files were compiled with -parameters flag.但是,只有在使用-parameters标志编译 Java 文件时才能检索参数名称。

You can obtain the names of the formal parameters of any method or constructor with the method java.lang.reflect.Executable.getParameters.您可以使用 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 . (Method 和 Constructor 类扩展了 Executable 类,因此继承了 Executable.getParameters 方法。)但是,.class 文件默认不存储形式参数名称 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.这是因为许多生成和使用类文件的工具可能不希望包含参数名称的 .class 文件有更大的静态和动态占用空间。 In particular, these tools would have to handle larger .class files, and the Java Virtual Machine (JVM) would use more memory.特别是,这些工具必须处理更大的 .class 文件,而 Java 虚拟机 (JVM) 将使用更多内存。 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 .要将形式参数名称存储在特定的 .class 文件中,从而使反射 API 能够检索形式参数名称,请使用 -parameters 选项将源文件编译为 javac 编译器

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

How to instruct Eclipse to compile my web application with -parameters so I could later start Tomcat server in Eclipse with my code compiled with -parameters ?如何指示 Eclipse 使用-parameters编译我的 Web 应用程序,以便我稍后可以使用使用-parameters编译的代码在 Eclipse 中启动 Tomcat 服务器?

Eclipse 有自己的 Java 编译器,可以在项目 > 属性:Java 编译器中通过勾选最后一个复选框来设置-parameters标志的等效项:存储有关方法参数的信息(可通过反射使用) (默认情况下未启用,需要 Java 8 或更高)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM