[英]Java Maven Build: Thread.sleep doesn't work (in eclipse it does)
I've got a strange error. 我有一个奇怪的错误。 My code is the following:
我的代码如下:
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);
}
My goal is to login to the League of Legends servers using the open source riotapi: https://github.com/loldevs/riotapi/ 我的目标是使用开源riotapi登录到英雄联盟服务器: https : //github.com/loldevs/riotapi/
The problem isn't LoL specific, so no problem there. 问题不是特定于LoL的,因此那里没有问题。 When I create the
QueueTimer
, it needs some time to retrieve some data from the server, otherwise timer.getPosition()
will throw a NullPointerException
. 创建
QueueTimer
,需要一些时间才能从服务器检索一些数据,否则timer.getPosition()
将抛出NullPointerException
。 That's why I wait 6 seconds before going on. 这就是为什么我要等6秒钟才能继续。 In Eclipse debugging it all works fine, but after exporting it with
m2eclipse
(clean package as goals; I'm new to Maven if that matters), the compiled JAR doesn't sleep. 在Eclipse调试中,一切正常,但是使用
m2eclipse
(干净的程序包作为目标;如果很重要,我是Maven新手)将其导出后,编译的JAR不会休眠。 It just goes on and then throws my NullPointerException
because it didn't wait. 它只是继续,然后抛出我的
NullPointerException
因为它没有等待。 Why does my code behave in Eclipse and doesn't work outside? 为什么我的代码在Eclipse中运行而不能在外部运行? What am I doing wrong?
我究竟做错了什么? I've tried
Thread.sleep()
instead of Thread.currentThread().sleep()
, doesn't work either. 我试过
Thread.sleep()
而不是Thread.currentThread().sleep()
,也不起作用。
Edit: 编辑:
I changed it to: 我将其更改为:
LoginQueue queue = new LoginQueue(server);
String authkey = queue.waitInQueueBlocking(this.username, this.password);
So I am using synchronous methods now. 所以我现在正在使用同步方法。 Now I get the following stacktrace:
现在,我得到以下堆栈跟踪:
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)
The error seems to be somewhere in the Riot API. 该错误似乎在Riot API中。 But why does it work inside eclipse?
但是为什么它在eclipse中起作用? I am too stupid to understand the API source, would be so cool if someone helped (Github is https://github.com/loldevs/riotapi/ ).
我太愚蠢,无法理解API的源代码,如果有人帮助的话,它会很棒(Github是https://github.com/loldevs/riotapi/ )。 My pom.xml: http://pastebin.com/jik5ba8J
我的pom.xml: http : //pastebin.com/jik5ba8J
Hey fellow ${search engine of choice}ers! 嗨,$ {搜索引擎之选}同胞们!
I had the same problem when running the .jar of my application which was built by maven. 运行由maven构建的应用程序的.jar时,我遇到了同样的问题。
Turns out that 原来是
I replaced the assembly plugin with the one-jar plugin (which adds dependencies as jar files in the produced binary) and after this everything worked fine. 我用一个jar插件替换了程序集插件(该插件将依赖项作为jar文件添加到生成的二进制文件中),然后一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.