Gradle + Javax:找不到实现类

时间:2018-07-02 22:09:26

标签: java gradle

我正在尝试构建Java项目,并且遇到导入javax库的问题。这是我的gradle文件:

buildscript {
    repositories {
      maven { url 'https://plugins.gradle.org/m2/' }
    }
  dependencies {
    classpath 'com.netflix.nebula:gradle-ospackage-plugin:4.3.0'
    // https://mvnrepository.com/artifact/org.eclipse.jetty.websocket/websocket-client
    //  compile group: 'org.eclipse.jetty.websocket', name: 'websocket-client', version: '9.4.11.v20180605'
  }
}

apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'nebula.ospackage-application'
apply plugin: 'maven'

group = 'ai.swim'
description = "Illustrate basic Swim concepts- ValueLane, MapLane, CommandLane, Recon and Java Objects"
sourceCompatibility = 1.8

repositories {

  maven {
    url 'https://repo.swim.it/swim-public/'
  }
  jcenter()
  mavenCentral()
}

configurations.all {
  resolutionStrategy {
    cacheChangingModulesFor 3600, 'seconds'
  }
}

dependencies {
  compile 'ai.swim:swim-server-client:1.2.0.20180531204107'
  compile group: 'org.eclipse.jetty.websocket', name: 'websocket-client', version: '9.4.11.v20180605'
  // https://mvnrepository.com/artifact/javax.websocket/javax.websocket-api
  compile group: 'javax.websocket', name: 'javax.websocket-api', version: '1.1'
}

configurations {
  testCompile.exclude group: 'ai.swim:swim-server'
}

compileJava {
  options.compilerArgs += ['-Xlint']
}

javadoc {
  options.charSet = 'UTF-8'
}

task runMain(type: JavaExec) {
  main = mainClassName
  systemProperties System.properties
}

task runClient(type: JavaExec) {
  main = 'ai.swim.client.Client'
  classpath = sourceSets.test.runtimeClasspath
  systemProperties System.properties
}

mainClassName = 'ai.swim.App'

例如,当我尝试使用javax-websockets库中的任何内容时,

import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;

Eclipse将所有这些行标记为错误。但是,它仍然可以编译并运行,但是它将在运行时失败并显示错误:

:compileJava
:processResources NO-SOURCE
:classes
:compileTestJava
:processTestResources NO-SOURCE
:testClasses
:runClientjava.lang.RuntimeException: Could not find an implementation class.
    at javax.websocket.ContainerProvider.getWebSocketContainer(ContainerProvider.java:73)
    at ai.swim.client.WebsocketClientEndpoint.<init>(WebsocketClientEndpoint.java:26)
    at ai.swim.client.Client.connectToBasestation2(Client.java:59)
    at ai.swim.client.Client.main(Client.java:50)
Exception in thread "main" java.lang.NullPointerException
    at ai.swim.client.WebsocketClientEndpoint.sendMessage(WebsocketClientEndpoint.java:84)
    at ai.swim.client.Client.connectToBasestation2(Client.java:69)
    at ai.swim.client.Client.main(Client.java:50)
 FAILED

我对此进行了很多尝试,例如,我尝试绕过mavenCentral()声明,尝试使用不同的指令(有人建议使用compileOnly而不是compile error: package javax.websocket does not exist)。 Maven存储库建议使用provided group而不是compile group,但这也不起作用。

对于上下文,我正在尝试从我发现的这种简洁的SWIM服务中引入一些WebSocket信息,但是出现了问题。我正在尝试实现在this StackOverflow article处找到的解决方案,以将我的WebSocket数据带入应用程序中。产生错误的代码来自WebsocketClientEndpoint.java

    public WebsocketClientEndpoint(URI endpointURI) {
        try {
            WebSocketContainer container = ContainerProvider.getWebSocketContainer();
            container.connectToServer(this, endpointURI);
        } catch (Throwable t) {
          t.printStackTrace();
//            throw new RuntimeException(e);
        }
    }

0 个答案:

没有答案