Apache轴记录-在Jira插件中使用它时发生ClassCastException [英] Apache axis logging - ClassCastException while using it inside a Jira plugin
问题描述
我的Jira 5.0插件已损坏,但有以下例外:
My Jira 5.0 plugin is broken with the following exception:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
Caused by: java.lang.ExceptionInInitializerError
at org.apache.axis.description.OperationDesc.<clinit>(OperationDesc.java:65)
at com.xyz.germander.AddTestTrackLinkDialogAction.doConfirm(AddTestTrackLinkDialogAction.java:23)
... 148 more
Caused by: java.lang.ClassCastException: org.apache.commons.logging.impl.SLF4JLogFactory cannot be cast to org.apache.commons.logging.LogFactory
at org.apache.axis.components.logger.LogFactory.getLogFactory(LogFactory.java:41)
at org.apache.axis.components.logger.LogFactory.<clinit>(LogFactory.java:33)
... 150 more
作为参考,这是引发ClassCastException的方法:
For reference, this is the method throwing the ClassCastException:
private static final org.apache.commons.logging.LogFactory getLogFactory() {
return (org.apache.commons.logging.LogFactory)
AccessController.doPrivileged(
new PrivilegedAction() {
public Object run() {
return DiscoverSingleton.find(org.apache.commons.logging.LogFactory.class,
org.apache.commons.logging.LogFactory.FACTORY_PROPERTIES,
org.apache.commons.logging.LogFactory.FACTORY_DEFAULT);
}
});
}
...作为进一步参考,org.apache.commons.logging.LogFactory.FACTORY_DEFAULT是"org.apache.commons.logging.impl.LogFactoryImpl",而FACTORY_PROPERTIES应该是要搜索的属性文件的名称为此,在我的org.apache.commons.logging jar中是"commons-logging.properties".
... for further reference, org.apache.commons.logging.LogFactory.FACTORY_DEFAULT is "org.apache.commons.logging.impl.LogFactoryImpl", and FACTORY_PROPERTIES is supposed to be the name of the properties file to search for, which in my org.apache.commons.logging jar is "commons-logging.properties".
我尝试在插件的资源目录中创建commons-logging.properties文件;该文件包含以下内容:
I've tried creating a commons-logging.properties file in the resource dir of the plugin; that file contains this:
priority=1
org.apache.commons.logging.Log=org.apache.commons.logging.impl.LogFactoryImpl
...但是它似乎被忽略了,因为getLogFactory()仍然获取SLF4JLogFactory并且无法强制转换.因此,它看起来像:
... but it seems to get ignored since getLogFactory() still gets SLF4JLogFactory and fails to cast it. So it looks like:
- 此commons-logging.properties文件需要放在其他位置
- 我需要将日志记录类设置为其他类型
- 该项目的配置不正确,可能是在Jira级别或在插件上,或者是在Maven或...我什至不知道
我很困惑,不胜感激.
I'm pretty stumped, and would appreciate any guidance.
在此处,不同之处在于发帖人从org.apache.axis.attachments.AttachmentsImpl而不是org.apache.axis.description.OperationDesc的初始化中在getLogFactory中得到了相同的异常. (也是Confluence插件,不是Jira.)但是,没有人对此做出回应.
There is a similar question here, except that poster was getting the same exception in getLogFactory from the initialization of org.apache.axis.attachments.AttachmentsImpl instead of org.apache.axis.description.OperationDesc. (Also a Confluence plugin, not Jira.) Nobody responded there, though.
推荐答案
发现:Atlassian分叉了轴库,而Jira现在使用的是axis-1.3-atlassian-1,而不是Apache的最新的axis-1.4. axis-1.3-atlassian-1使用commons-logging的1.0.4版本,而不是像axis-1.4那样的1.1.1版本.
Discoveries: Atlassian forked the axis library and Jira now uses axis-1.3-atlassian-1 and not the latest axis-1.4 from Apache; axis-1.3-atlassian-1 uses the 1.0.4 version of commons-logging, not 1.1.1 like axis-1.4.
将插件的依赖性从axis-1.4更改为axis-1.3-atlassian-1可以解决此问题.我怀疑SLF4JLogFactory可以在1.0.4中转换为org.apache.commons.logging.LogFactory,但不能在1.1.1中转换,但我尚未对其进行测试.
Changing the dependency of the plugin from axis-1.4 to axis-1.3-atlassian-1 solved the problem. It is my suspicion that SLF4JLogFactory could cast to org.apache.commons.logging.LogFactory in 1.0.4 but not 1.1.1, but I haven't tested it.
如果在Jira中,请确保将依赖项的范围设置为提供",否则由于将内容加载两次而会遇到问题.这是pom片段:
If in Jira, be sure to give the scope of the dependency as "provided" or you'll run in to problems due to stuff being loaded twice. Here's a pom snippet:
<dependency>
<groupId>axis</groupId>
<artifactId>axis</artifactId>
<version>1.3-atlassian-1</version>
<scope>provided</scope>
</dependency>
这篇关于Apache轴记录-在Jira插件中使用它时发生ClassCastException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!