2 Replies Latest reply on Oct 22, 2017 11:24 PM by rshah RSS
    rshah Newbie

    java sdk not working with docker

    Hi,

     

    I was trying to use the Thingworx java sdk with docker to build an image out of it and use it as a docker container. I followed the following steps:

     

    1) I loaded the application into eclipse

    2) I ran gradel build gradle Build from eclipse which exported the app as a jar

    3) I built an image using "docker build -t imagename ." in the directory of the jar

    4) docker run imagename

     

    This throws an error saying mainclass not found

     

    I tried running the jar exported using java -jar filename.jar That throws the same error. Below is my build.gradle file

     

     

    /*

    Install gradle at https://gradle.org/ and execute 'gradle run' or 'gradle SimpleClient'

    in this directory to run an example. Other examples can be run

    with the commands 'gradle SimpleThing' and 'gradle Steam'.

     

     

    You can also generate an Eclipse project with the command 'gradle eclipse' or

    install the gradle eclipse plugin from the Eclipse Marketplace and Import it into eclipse.

    */

    apply plugin: 'java'

    apply plugin: 'application'

    //apply plugin: 'docker'

    apply plugin: 'eclipse'

     

     

    sourceCompatibility = 1.7

    targetCompatibility = 1.7

    version = '1.0'

     

     

    mainClassName = "com.thingworx.sdk.simplething.SimpleThingClient"

     

     

    // Customize the settings below to run the SteamClient

    project.ext {

    serverUrl = "ws://localhost:8080/Thingworx/WS"

    appKey = "f5966263-ea1b-4ebf-ae0a-8467fa65469c"  // Create this in Thingworx xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

    scanRate = "1000" //ms

    numberOfSensors = "10" // The number of sensors to create

    startSensor = "1" // The starting number for the first sensor

    }

     

     

    jar{

    manifest {

            attributes ('Main-Class': 'com.thingworx.sdk.simplething.SimpleThingClient.class')

            }

        }

     

     

    sourceSets {

    main {

    java {

    srcDir 'src'

    }

    resources {

    srcDir 'resources'

    }

     

     

    }

    }

     

     

    buildscript {

      repositories {

        //this plugin will be pulled from jcenter

        jcenter()

      }

    }

     

     

    dependencies {

    compile fileTree(dir: '../lib', include: ['*.jar'])

    //classpath 'se.transmode.gradle:gradle-docker:1.2'

    }

     

     

     

     

    task SimpleClient(type: JavaExec) {

    dependsOn "build"

    classpath = sourceSets.main.runtimeClasspath

    main = "com.thingworx.sdk.simple.SimpleClient"

    }

     

     

     

     

    task SimpleThing(type: JavaExec) {

    dependsOn "build"

    classpath = sourceSets.main.runtimeClasspath

    main = "com.thingworx.sdk.simplething.SimpleThingClient"

    }

     

     

    task Steam(type: JavaExec) {

    dependsOn "build"

    classpath = sourceSets.main.runtimeClasspath

    main = "com.thingworx.sdk.steam.SteamSensorClient"

    args project.ext.serverUrl,project.ext.appKey,project.ext.scanRate,project.ext.startSensor,project.ext.numberOfSensors

    }

     

     

    Below is the error message (This is the only line that prints)

    "Error: Could not find or load main class com.thingworx.sdk.simplething.SimpleThingClient.class"

     

    using same process other apps that I worked on previously not involving Thingworx does not throw this issue

      • Re: java sdk not working with docker
        carko Creator

        Hello, Rishit Shah.

         

        I'm not familiar with the gradle plugin but I did notice this:

         

        apply plugin: 'java'

        apply plugin: 'application'

        //apply plugin: 'docker'

        apply plugin: 'eclipse'

         

        Should the Docker plugin be commented out here when doing the build?

         

        -- Craig A.

          • Re: java sdk not working with docker
            rshah Newbie

            Hi Craig,

             

            Yes I commented that out on purpose as it was throwing another error saying "plugin not found". I used a workaround instead and tried built the image including the jar exported from this gradle file. But then I ran into the above issue.