簡體   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