Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将方法参数名称持久化为字节码,以便在使用Maven构建时通过反射可以使用它们_Java_Maven_Reflection_Build - Fatal编程技术网

Java 将方法参数名称持久化为字节码,以便在使用Maven构建时通过反射可以使用它们

Java 将方法参数名称持久化为字节码,以便在使用Maven构建时通过反射可以使用它们,java,maven,reflection,build,Java,Maven,Reflection,Build,要使用反射,我需要存储有关方法参数的信息 可以通过以下方式从eclipse手动完成 窗口->首选项->Java->编译器 但是如何通过maven build实现这一点呢 import java.lang.reflect.Method; import java.lang.reflect.Parameter; public class GetParams { public static void main(String[] args) throws Exception {

要使用反射,我需要存储有关方法参数的信息

可以通过以下方式从eclipse手动完成 窗口->首选项->Java->编译器

但是如何通过maven build实现这一点呢

import java.lang.reflect.Method;  
import java.lang.reflect.Parameter;


public class GetParams {

       public static void main(String[] args) throws Exception {
             Method method = MyInterface.class.getMethod("myway", String.class);
             Parameter p = m.getParameters()[0];
             System.out.println(p.isNamePresent());
             System.out.println(p.getName());
        }  

        public interface MyInterface {
             String myway(String str);
        }  
  }

要在生成的字节码中存储参数名,必须将-parameters标志传递给java编译器。如果您使用过maven,可以通过maven编译器插件:


是正确的AKI测试有单独的参数testCompilerArgument
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
      <compilerArgs>
        <arg>-parameters</arg>
      </compilerArgs>
    </configuration>
  </plugin>
</plugins>