gpt4 book ai didi

java - 为什么maven会抛出InvocableTargetException?

转载 作者:行者123 更新时间:2023-12-01 23:53:36 24 4
gpt4 key购买 nike

我从命令行运行 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com