gpt4 book ai didi

java - 渲染宏出错 - 无法初始化类 org.apache.xmlrpc.util.SAXParsers

转载 作者:太空宇宙 更新时间:2023-11-04 12:25:22 28 4
gpt4 key购买 nike

我正在创建 confluence 宏,它应该执行我的 Java xml-rpc 客户端。

我测试了我的 Java xml-rpc 客户端,在 eclipse 中终止它(主要功能)- 它工作完美,

但是当我尝试将其与 confluence 连接时,我收到错误:

(宏已成功安装 - 输出出现错误)

Error rendering macro 'TESTLINK PLUGIN' : Could not initialize class org.apache.xmlrpc.util.SAXParsers

有人可以帮我理解这里发生了什么吗?我读到这可能是外部 jar 的问题 - 但给出的答案并不能解决我的问题。

我还使用mvn-install命令安装了我的xmlrpc,并将依赖项添加到我的pom.xml中,SAXParsers应该包含在那里......

这是我到目前为止所做的代码:

teSTLink.java:

package com.project.testlink.api;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Map;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
public class testlink {
public testlink() {
// TODO Auto-generated constructor stub
}

// Substitute your Dev Key Here
public static final String DEV_KEY = "zzzzZZz";
// Substitute your Server URL Here
public static final String SERVER_URL = "zzzZZZZ/xmlrpc.php";

public static String testLinkReport(String link)
{
String title="Error Ocurred";
String tcid = link.substring(link.lastIndexOf("=")+1);
try
{
XmlRpcClient rpcClient;
XmlRpcClientConfigImpl config;

config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL(SERVER_URL));
rpcClient = new XmlRpcClient();
rpcClient.setConfig(config);

ArrayList<Object> params = new ArrayList<Object>();
Hashtable<String, Object> executionData = new Hashtable<String, Object>();

executionData.put("devKey", DEV_KEY);
executionData.put("testcaseexternalid", tcid);
params.add(executionData);
Object[] result = (Object[]) rpcClient.execute("tl.getTestCase", params);

Map item = (Map)result[0];
title = tcid+":"+ item.get("name").toString();


}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (XmlRpcException e)
{
e.printStackTrace();
}
return title;
}

}

mymacro.java:

package com.project.testlink.api;
import java.util.Map;
import com.atlassian.confluence.content.render.xhtml.ConversionContext;
import com.atlassian.confluence.macro.Macro;
import com.atlassian.confluence.macro.MacroExecutionException;

public class mymacro implements Macro {
public mymacro() {
// TODO Auto-generated constructor stub
}
@Override
public String execute(Map<String, String> arg0, String arg1, ConversionContext arg2)
throws MacroExecutionException {
// TODO Auto-generated method stub

return testlink.testLinkReport("HL&item=testcase&id=7780");
}
@Override
public BodyType getBodyType() {
// TODO Auto-generated method stub
return BodyType.NONE;
}
@Override
public OutputType getOutputType() {
// TODO Auto-generated method stub
return OutputType.BLOCK;
}
/*
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(testlink.testLinkReport("HL&item=testcase&id=7780"));
}
*/

}

atlassian-plugin.xml:

<atlassian-plugin key="${atlassian.plugin.key}" name="${project.name}" plugins-version="2">
<plugin-info>
<description>${project.description}</description>
<version>${project.version}</version>
<vendor name="${project.organization.name}" url="${project.organization.url}" />
<param name="plugin-icon">images/pluginIcon.png</param>
<param name="plugin-logo">images/pluginLogo.png</param>
</plugin-info>
<!-- add our i18n resource -->
<resource type="i18n" name="i18n" location="testlink"/>

<xhtml-macro name="TESTLINK PLUGIN" class="com.project.testlink.api.mymacro" key="mymacro" icon="/download/resources/${project.groupId}.${project.artifactId}/images/pluginIcon.png">
<category name="external-content"/>
<parameters>
<parameter name="Testlink" type="string" required="true"/>
</parameters>
<description>Inserts a calendar for the week into the current page</description>
</xhtml-macro>


<!-- add our web resources -->
<web-resource key="testlink-resources" name="testlink Web Resources">
<dependency>com.atlassian.auiplugin:ajs</dependency>

<resource type="download" name="testlink.css" location="/css/testlink.css"/>
<resource type="download" name="testlink.js" location="/js/testlink.js"/>
<resource type="download" name="images/" location="/images"/>
<context>testlink</context>
</web-resource>

</atlassian-plugin>

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.project.testlink</groupId>
<artifactId>testlink</artifactId>
<version>1.0.0-SNAPSHOT</version>
<organization>
<name>Example Company</name>
<url>http://www.example.com/</url>
</organization>
<name>testlink</name>
<description>This is the com.project.testlink:testlink plugin for Atlassian Confluence.</description>
<packaging>atlassian-plugin</packaging>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.atlassian.confluence</groupId>
<artifactId>confluence</artifactId>
<version>${confluence.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-annotation</artifactId>
<version>${atlassian.spring.scanner.version}</version>
<scope>compile</scope>
</dependency>


<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-runtime</artifactId>
<version>${atlassian.spring.scanner.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<scope>provided</scope>
</dependency>
<!-- WIRED TEST RUNNER DEPENDENCIES -->
<dependency>
<groupId>com.atlassian.plugins</groupId>
<artifactId>atlassian-plugins-osgi-testrunner</artifactId>
<version>${plugin.testrunner.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.2-atlassian-1</version>
</dependency>
<dependency>
<groupId>org.apache.xmlrpc</groupId>
<artifactId>xml-common</artifactId>
<version>3.1.3</version>
</dependency>
<dependency>
<groupId>org.apache.xmlrpc</groupId>
<artifactId>xml-client</artifactId>
<version>3.1.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-confluence-plugin</artifactId>
<version>${amps.version}</version>
<extensions>true</extensions>
<configuration>
<productVersion>${confluence.version}</productVersion>
<productDataVersion>${confluence.data.version}</productDataVersion>
<enableQuickReload>true</enableQuickReload>
<enableFastdev>false</enableFastdev>
<!-- See here for an explanation of default instructions: -->
<!-- https://developer.atlassian.com/docs/advanced-topics/configuration-of-instructions-in-atlassian-plugins -->
<instructions>
<Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>
<!-- Add package to export here -->
<Export-Package>
com.project.testlink.api,
</Export-Package>
<!-- Add package import here -->
<Import-Package>
org.springframework.osgi.*;resolution:="optional",
org.eclipse.gemini.blueprint.*;resolution:="optional",
*
</Import-Package>
<!-- Ensure plugin is spring powered -->
<Spring-Context>*</Spring-Context>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-maven-plugin</artifactId>
<version>1.2.6</version>
<executions>
<execution>
<goals>
<goal>atlassian-spring-scanner</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
<configuration>
<scannedDependencies>
<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-external-jar</artifactId>
</dependency>
</scannedDependencies>
<verbose>false</verbose>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<confluence.version>5.10.2</confluence.version>
<confluence.data.version>5.10.1</confluence.data.version>
<amps.version>6.2.4</amps.version>
<plugin.testrunner.version>1.2.3</plugin.testrunner.version>
<atlassian.spring.scanner.version>1.2.6</atlassian.spring.scanner.version>
<!-- This key is used to keep the consistency between the key in atlassian-plugin.xml and the key to generate bundle. -->
<atlassian.plugin.key>${project.groupId}.${project.artifactId}</atlassian.plugin.key>
</properties>
</project>

最佳答案

问题已解决。

向依赖项添加了“排除”,例如 here

之后我必须从 .jar 文件中删除 SAXParsers 类,现在它可以工作了:)

The problem is that the Apache XML-RPC client library you are using has a multitude of other dependencies that it will bundle into your plugin when you compile, and they clash with libraries already shipped in JIRA.

关于java - 渲染宏出错 - 无法初始化类 org.apache.xmlrpc.util.SAXParsers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38445527/

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