Question

I am running maven from the command line

mvn exec:java -Dexec.mainClass=org.xmlcml.svg2xml.analyzer.DocumentListAnalyzer 
   -Dexec.args=.

When my program throws a RuntimeException, maven does not throw this but throws a InvocationTargetException

java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
        at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.RuntimeException: Only one primary allowed for 3 line textL
ineGroup
        at org.xmlcml.svg2xml.text.TextLineGroup.createSuscriptTextLineList(Text
LineGroup.java:181)
        at org.xmlcml.svg2xml.text.TextLineGroup.createHtml(TextLineGroup.java:2
40)

This does not happen when running Eclipse.

Why does this happen? (It confused me and confuses my users).

Était-ce utile?

La solution

The Invoking Methods told us as the following: -

Reflection provides a means for invoking methods on a class. Typically, this would only be necessary if it is not possible to cast an instance of the class to the desired type in non-reflective code.

Methods are invoked with java.lang.reflect.Method.invoke(). The first argument is the object instance on which this particular method is to be invoked. (If the method is static, the first argument should be null.) Subsequent arguments are the method's parameters.

If the underlying method throws an exception, it will be wrapped by an java.lang.reflect.InvocationTargetException. The method's original exception may be retrieved using the exception chaining mechanism's InvocationTargetException.getCause() method.

Since the stacktrace also told us that the exec:java also uses the Reflection as well. Then the original exception is also wrapped as well. Please refer to the source code of at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297) for further reference.

I hope this may help.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top