运行Eclipse与M2 Maven构建忽略“存储方法参数名称”定义 [英] Run Eclipse with M2 Maven build ignores "Store method parameter names" definition
问题描述
我的应用程序使用反射来提取特定方法的参数名称。
我需要像我们的代码中写的名称(而不是arg0,arg1 ...)
为了实现这一点,我去:
Windows - >首选项 - > Java - >编译器 - 并标记:存储方法参数名称。
(我用Eclipse Kepler使用JDK1.8)
现在,当我做某事喜欢:
method.getParameters()[0] .getName()
/ pre>
如果我使用Debug Configuration = Java应用程序运行我的应用程序 - >它工作正常!
如果我使用Debug Configuration = M2 Maven Build - >运行它,那么它不起作用!它显示合成名称(arg0,arg1 ...)
我需要它通过Maven Build工作,任何想法?
解决方案尝试明确告诉编译器你想要保留方法参数名称:
code><插件>
< 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>
My application uses reflection in order to extract parameters names for a specific method.
I need the names like they are written in my code (and not arg0, arg1...).
In order to achieve this I go to: Windows -> Preferences -> Java -> Compiler - and mark: "Store method parameter names".
(I use JDK1.8 with Eclipse Kepler)
Now, when I do something like:
method.getParameters()[0].getName()
If I run my application with Debug Configuration = Java application --> it works fine!
BUT, if I run it with Debug Configuration = M2 Maven Build --> it doesn't work! it show the synthesize names (arg0, arg1...)
I need it to work via Maven Build, Any idea??
解决方案Try to explicitly tell compiler that you want method parameter names to be preserved:
<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>
这篇关于运行Eclipse与M2 Maven构建忽略“存储方法参数名称”定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!