3

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??

Shvalb
  • 1,835
  • 2
  • 30
  • 60

1 Answers1

5

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>
Jk1
  • 11,233
  • 9
  • 54
  • 64
  • OOOPPSS, I was happy to early... I tried it for the first time and it worked, and when I tried again it didn't!! VERY VERY STRANGE! – Shvalb Jun 05 '14 at 12:47
  • 3
    Found the solution: -parameters -parameters – Shvalb Jun 05 '14 at 14:05
  • thanks for sharing it, I totally forgot that there's a separate param string for tests – Jk1 Jun 05 '14 at 14:24
  • Did you add this in the parent or in the child poms? You wouldn't happen to still have a working solution would you? – mad_fox Dec 19 '17 at 23:58