java - 为什么maven会抛出InvocableTargetException?

标签 java maven invocationtargetexception

我从命令行运行 Maven

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

当我的程序抛出一个 RuntimeException 时,maven 不会抛出这个异常,而是抛出一个 InitationTargetException

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)

运行 Eclipse 时不会发生这种情况。

为什么会发生这种情况? (它让我感到困惑,也让我的用户感到困惑)。

最佳答案

Invoking Methods告诉我们如下:-

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.

因为堆栈跟踪还告诉我们,exec:java 也使用了Reflection。然后原始异常也被包装。请引用 org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297) 的源码以供进一步引用。

希望这会有所帮助。

关于java - 为什么maven会抛出InvocableTargetException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15966662/

相关文章:

java - Java在canvas之外绘制东西,会不会影响性能?

JavaFx:如果我想在 initialize() 之后,场景显示之前做一些事情,我该如何实现呢?

java - 如何使用 Java 中的 HashMap 将名称与组织中的成员资格进行匹配?

postgresql - maven java.lang.ClassNotFoundException : org. postgresql.Driver

按下 Pane 中的按钮时发生 JavaFX InvokingTargetException

Java 类型转换 - float(和 long)到 int

scala - sbt- ManagedStyle.Maven

java - 部署在 ActiveMQ 内部时的 Camel log4j 配置

java - 在 driver=new ChromeDriver(); 行上获取 "InvocationTargetException"异常;

java - 如何解决for循环中的InvocableTargetException? (寻找整个堆栈跟踪)