2015-08-13 71 views
3

我以前在Java中创建了一个稳定的客户端应用程序来批量操纵票据并加速工作流,但是,我想创建一个更全面的应用程序,它利用实际的JIRA API而不是解析JSON自己解决。 我有一个非常简单的代码块创建一个客户端:无法创建AsynchronousJiraRestClientFactory(依赖项问题)

public class SimpleMain { 
    public static void main(String[] args) { 
    try { 
     JiraRestClient client = new AsynchronousJiraRestClientFactory() 
     .createWithBasicHttpAuthentication(new URI("https://jira.redacted.com"), "redacted", "redacted"); 
    } catch (URISyntaxException e) { 
     e.printStackTrace(); 
    } 
    } 
} 

试图创建以下异常简单AsynchronousJiraRestClientFactory结果:

15:12:06.625 [main] DEBUG c.a.j.r.c.i.a.AsynchronousHttpClientFactory$MavenUtils - Could not find version for maven artifact com.atlassian.jira:jira-rest-java-com.atlassian.jira.rest.client 
15:12:06.633 [main] DEBUG c.a.j.r.c.i.a.AsynchronousHttpClientFactory$MavenUtils - Got the following exception 
java.lang.NullPointerException: null 
at java.util.Properties$LineReader.readLine(Properties.java:434) ~[na:1.8.0_51] 
at java.util.Properties.load0(Properties.java:353) ~[na:1.8.0_51] 
at java.util.Properties.load(Properties.java:341) ~[na:1.8.0_51] 
at com.atlassian.jira.rest.client.internal.async.AsynchronousHttpClientFactory$MavenUtils.getVersion(AsynchronousHttpClientFactory.java:158) ~[jira-rest-java-client-core-3.0.0.jar:na] 
at com.atlassian.jira.rest.client.internal.async.AsynchronousHttpClientFactory$RestClientApplicationProperties.getVersion(AsynchronousHttpClientFactory.java:121) [jira-rest-java-client-core-3.0.0.jar:na] 
at com.atlassian.httpclient.apache.httpcomponents.DefaultHttpClient.getUserAgent(DefaultHttpClient.java:168) [atlassian-httpclient-apache-httpcomponents-0.13.2.jar:na] 
at com.atlassian.httpclient.apache.httpcomponents.DefaultHttpClient.<init>(DefaultHttpClient.java:139) [atlassian-httpclient-apache-httpcomponents-0.13.2.jar:na] 
at com.atlassian.jira.rest.client.internal.async.AsynchronousHttpClientFactory.createClient(AsynchronousHttpClientFactory.java:53) [jira-rest-java-client-core-3.0.0.jar:na] 
at com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory.create(AsynchronousJiraRestClientFactory.java:35) [jira-rest-java-client-core-3.0.0.jar:na] 
at com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory.createWithBasicHttpAuthentication(AsynchronousJiraRestClientFactory.java:42) [jira-rest-java-client-core-3.0.0.jar:na] 
at jiratest.SimpleMain.main(SimpleMain.java:13) [classes/:na] 
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.http.nio.client.HttpAsyncClient.start()V 
at com.atlassian.httpclient.apache.httpcomponents.DefaultHttpClient.<init>(DefaultHttpClient.java:162) 
Disconnected from the target VM, address: '127.0.0.1:53429', transport: 'socket' 
at com.atlassian.jira.rest.client.internal.async.AsynchronousHttpClientFactory.createClient(AsynchronousHttpClientFactory.java:53) 
at com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory.create(AsynchronousJiraRestClientFactory.java:35) 
at com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory.createWithBasicHttpAuthentication(AsynchronousJiraRestClientFactory.java:42) 
at jiratest.SimpleMain.main(SimpleMain.java:13) 

从我一直在读什么,这是一个由于不同的库,因此存在依赖性问题。这是我用的:

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <java.version>1.8</java.version> 
    <pojomatic.version>2.0.1</pojomatic.version> 
    <jira-api.version>6.1.1</jira-api.version> 
    <jira-rest-java-client-core.version>3.0.0</jira-rest-java-client-core.version> 
    <httpcore.version>4.4.1</httpcore.version> 
    <commons-io.version>2.4</commons-io.version> 
</properties> 

<dependencies> 
    <dependency> 
     <groupId>com.atlassian.jira</groupId> 
     <artifactId>jira-api</artifactId> 
     <version>${jira-api.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>com.atlassian.jira</groupId> 
     <artifactId>jira-rest-java-client-core</artifactId> 
     <version>${jira-rest-java-client-core.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.httpcomponents</groupId> 
     <artifactId>httpclient</artifactId> 
     <version>${httpcore.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.httpcomponents</groupId> 
     <artifactId>httpcore</artifactId> 
     <version>${httpcore.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.httpcomponents</groupId> 
     <artifactId>httpcore-nio</artifactId> 
     <version>${httpcore.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.pojomatic</groupId> 
     <artifactId>pojomatic</artifactId> 
     <version>${pojomatic.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-batch</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-test</artifactId> 
     <scope>test</scope> 
    </dependency> 
</dependencies> 

有谁知道我应该使用什么版本?我仍然缺少依赖关系吗?我一直在阅读亚特兰大的q/a和各种谷歌文档,我认为我很接近,但我不确定我还缺少什么。

感谢所有提前:)

回答

4

实际问题的事实是奠定了Spring的传递依赖覆盖Atlassian的传递依赖。解决这个问题的方法是将依赖关系转换回jrjc需要它们的地方,而不是更新的版本。

<dependencyManagement> 
    <dependencies> 
    <dependency> 
     <groupId>org.apache.httpcomponents</groupId> 
     <artifactId>httpclient</artifactId> 
     <version>4.2.1-atlassian-2</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.httpcomponents</groupId> 
     <artifactId>httpasyncclient</artifactId> 
     <version>4.0-beta3-atlassian-1</version> 
    </dependency> 
    </dependencies> 
</dependencyManagement> 

注意:这些版本可能会在未来版本中更改,但它们适用于JRJC核心版本3.0.0。你可以通过阅读mvn dependency:tree的输出来找到它,它会这样说:httpasyncclient:jar:4.0.2:compile - version managed from 4.0-beta3-atlassian-1它让你知道maven正在使用版本4.0.2的httpsyncclient,所以你需要覆盖它回到4.0-beta3-atlassian-1

+0

在'依赖性:tree'我看到exaclty这两个依赖和增加你的建议的dependecyManagement部分没有帮助摆脱NullPointerException :( – dokaspar

+0

可能你有另一个与jrjc核心发生冲突的依赖项。运行'mvn dependency:tree'并查看你是否看到任何'受管理的'消息在dependencyManagement部分将它们拉到from版本,然后漂洗并重复。有时候,如果你有多个依赖关系,你实际上会被拉到多个ti mes,而不是一次给定的依赖关系,所以唯一的方法是知道多次管理/检查。 –

+0

@dokaspar这很可能已经太晚了,我只是意识到这可能是因为你需要清理你的老依赖的maven项目。 'mvn clean install -B -U'去除然后收集由pom文件定义的最新的依赖关系。 –

0

我已经得到了同样的问题,并解决它通过以下方式: 我在pom.xml文件中有两个

<dependency> 
    <groupId>com.atlassian.jira</groupId> 
    <artifactId>jira-rest-java-client-core</artifactId> 
    <version>2.0.0-m25</version> 
</dependency> 

<dependency> 
    <groupId>com.atlassian.httpclient</groupId> 
    <artifactId>atlassian-httpclient-apache-httpcomponents</artifactId> 
    <version>0.13.2</version> 
</dependency> 

。原来客户端内核已经有了httpcomponents,并且发生了冲突。卸下第二依赖固定的问题

0

试图在互联网上的所有其他解决方案后,修改我的log4j2配置为我工作:

<?xml version="1.0" encoding="UTF-8"?> 
<Configuration status="DEBUG"> 
<Appenders> 
    <Console name="Console" target="SYSTEM_OUT"> 
     <PatternLayout pattern="%msg%n" /> 
    </Console> 
    <File name="File" fileName="qed.log" immediateFlush="true" append="true"> 
     <PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> 
    </File> 
</Appenders> 
<Loggers> 
    <Logger name="com.atlassian.jira.rest.client.internal.async.AsynchronousHttpClientFactory$MavenUtils" level="OFF"/> 
    <Root level="DEBUG"> 
     <AppenderRef ref="Console" /> 
     <AppenderRef ref="File"/> 
    </Root> 
</Loggers> 

配置的关键部分是:

<Logger name="com.atlassian.jira.rest.client.internal.async.AsynchronousHttpClientFactory$MavenUtils" level="OFF"/> 

显然它不能解决问题,但它确实隐藏了它。

由于作为NullPointerException异常似乎是讨厌的,它对创建ApacheAsyncHttpClient没有影响,请参阅:

 try { 
      resourceAsStream = MavenUtils.class.getResourceAsStream(String 
        .format("/META-INF/maven/%s/%s/pom.properties", groupId, artifactId)); 
      props.load(resourceAsStream); 
      return props.getProperty("version", UNKNOWN_VERSION); 
     } catch (Exception e) { 
      logger.debug("Could not find version for maven artifact {}:{}", groupId, artifactId); 
      logger.debug("Got the following exception", e); 
      return UNKNOWN_VERSION; 
     } finally { 
+0

你必须回头看我的stacktrace:'在jiratest.SimpleMain.main(SimpleMain.java:13)',这实际上阻止了我的应用程序运行。所以,不幸的是,这与你所看到的不一样。 –