【问题标题】:Run Eclipse with M2 Maven build ignores "Store method parameter names" definition使用 M2 Maven 构建运行 Eclipse 忽略“存储方法参数名称”定义
【发布时间】:2014-06-05 09:24:35
【问题描述】:

我的应用程序使用反射来提取特定方法的参数名称。

我需要在我的代码中编写的名称(而不是 arg0、arg1...)。

为了实现这一点,我会: Windows -> 首选项 -> Java -> 编译器 - 并标记:“存储方法参数名称”。

(我使用JDK1.8和Eclipse Kepler)

现在,当我做类似的事情时:

method.getParameters()[0].getName() 

如果我使用 Debug Configuration = Java application 运行我的应用程序 --> 它工作正常!

但是,如果我使用 Debug Configuration = M2 Maven Build 运行它 --> 它不起作用!它显示合成名称 (arg0, arg1...)

我需要它通过 Maven Build 工作,知道吗?

【问题讨论】:

    标签: java eclipse maven maven-3


    【解决方案1】:

    尝试明确告诉编译器您希望保留方法参数名称:

    <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-compiler-plugin</artifactId>
       <version>3.1</version>
       <configuration>
          <source>1.8</source>
          <target>1.8</target>
          <compilerArgument>-g:vars</compilerArgument>
          <testCompilerArgument>-g:vars</testCompilerArgument>
       </configuration>
    </plugin>
    

    【讨论】:

    • OOOPPSS,我很高兴能早点......我第一次尝试它并且它有效,当我再次尝试时它没有!非常非常奇怪!
    • 找到解决方案:-parameters-parameters
    • 感谢分享,我完全忘记了测试有一个单独的参数字符串
    • 你是在父 pom 中还是在子 pom 中添加的?你不会碰巧还有一个可行的解决方案吧?
    猜你喜欢
    • 1970-01-01
    • 2015-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-26
    • 2011-11-02
    • 2012-06-16
    • 1970-01-01
    相关资源
    最近更新 更多