繁体   English   中英

Java Maven Build:Thread.sleep不起作用(在Eclipse中起作用)

[英]Java Maven Build: Thread.sleep doesn't work (in eclipse it does)

我有一个奇怪的错误。 我的代码如下:

    LoginQueue queue = new LoginQueue(server);
    QueueTimer timer = queue.waitInQueue(this.username, this.password);
    Thread.currentThread().sleep(6000);
    while (!timer.isFinished()) {

        if (timer.getPosition() != 0L) {
            log("Queue Position" + server.toString() + ":"
                    + String.valueOf(timer.getPosition()), LogLevel.DEBUG);
            Thread.currentThread().sleep(3000);
        }

我的目标是使用开源riotapi登录到英雄联盟服务器: https : //github.com/loldevs/riotapi/

问题不是特定于LoL的,因此那里没有问题。 创建QueueTimer ,需要一些时间才能从服务器检索一些数据,否则timer.getPosition()将抛出NullPointerException 这就是为什么我要等6秒钟才能继续。 在Eclipse调试中,一切正常,但是使用m2eclipse (干净的程序包作为目标;如果很重要,我是Maven新手)将其导出后,编译的JAR不会休眠。 它只是继续,然后抛出我的NullPointerException因为它没有等待。 为什么我的代码在Eclipse中运行而不能在外部运行? 我究竟做错了什么? 我试过Thread.sleep()而不是Thread.currentThread().sleep() ,也不起作用。

编辑:

我将其更改为:

LoginQueue queue = new LoginQueue(server);
String authkey = queue.waitInQueueBlocking(this.username, this.password);

所以我现在正在使用同步方法。 现在,我得到以下堆栈跟踪:

Exception in thread "Queue Timer for LeagueAlerter" java.lang.NullPointerException
        at org.apache.cxf.jaxrs.client.AbstractClient.setupOutInterceptorChain(AbstractClient.java:840)
        at org.apache.cxf.jaxrs.client.AbstractClient.createMessage(AbstractClient.java:902)
        at org.apache.cxf.jaxrs.client.WebClient.finalizeMessage(WebClient.java:1068)
        at org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1049)
        at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:854)
        at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:825)
        at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:393)
        at org.apache.cxf.jaxrs.client.WebClient$SyncInvokerImpl.method(WebClient.java:1582)
        at org.apache.cxf.jaxrs.client.WebClient$SyncInvokerImpl.method(WebClient.java:1577)
        at org.apache.cxf.jaxrs.client.WebClient$SyncInvokerImpl.post(WebClient.java:1517)
        at org.apache.cxf.jaxrs.client.spec.InvocationBuilderImpl.post(InvocationBuilderImpl.java:141)
        at net.boreeas.riotapi.loginqueue.LoginQueue.getAuthToken(LoginQueue.java:54)
        at net.boreeas.riotapi.loginqueue.QueueTimer.run(QueueTimer.java:89)

该错误似乎在Riot API中。 但是为什么它在eclipse中起作用? 我太愚蠢,无法理解API的源代码,如果有人帮助的话,它会很棒(Github是https://github.com/loldevs/riotapi/ )。 我的pom.xml: http//pastebin.com/jik5ba8J

嗨,$ {搜索引擎之选}同胞们!

运行由maven构建的应用程序的.jar时,我遇到了同样的问题。

原来是

  1. 我正在使用maven程序集插件生成jar。 该插件将(至少默认情况下)将所有依赖项资源直接放入生成的jar文件中
  2. CXF有一些重叠的资源(由于第1点,这意味着麻烦)

我用一个jar插件替换了程序集插件(该插件将依赖项作为jar文件添加到生成的二进制文件中),然后一切正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM