Community Tip - You can change your system assigned username to something more personal in your community settings. X
Hello,
I'm trying the Java SDK (java-sdk-6.1.0.679) with Gradle, i followed the ThingWorx_Edge_Java_SDK_Developers_Guide_v6.1.0 PDF steps and was able to connect my the SDK to my platform using the gradle SimpleThingClient command, now i need to generate a Jar file, after the generation i get this error :
Command : java -jar samples-1.0.jar
Error: Could not find or load main class com.thingworx.sdk.simplething.SimpleThingClient
My build.gradle :
/*
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: 'eclipse'
sourceCompatibility = 1.7
targetCompatibility = 1.7
version = '1.0'
mainClassName = "com.thingworx.sdk.SimpleClient.SimpleThingClient"
// Customize the settings below to run the SteamClient
project.ext {
serverUrl = "ws://192.168.0.163/Thingworx/WS"
appKey = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" // 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
}
sourceSets {
main {
java {
srcDir 'src'
}
resources {
srcDir 'resources'
}
}
}
dependencies {
compile fileTree(dir: '../lib', include: ['*.jar'])
}
jar {
manifest {
attributes(
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
'Main-Class': 'com.thingworx.sdk.simplething.SimpleThingClient'
)
}
}
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
}
Thanks,
Solved! Go to Solution.
Finally, i found a solution, here is how i fixed the my build.gradle;
1- you need to create a jar file with dependencies, i found this tutorial :https://www.mkyong.com/gradle/gradle-create-a-jar-file-with-dependencies/
2- added this code to my build.gradle :
/create a single Jar with all dependencies
task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': version,
'Main-Class': 'com.thingworx.sdk.simplething.SimpleThingClient'
}
baseName = project.name + '-all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
3- clean the project with => $ gradle clean
4-Run the Gradle fatJar
task => $ gradle fatJar
voila;
Finally, i found a solution, here is how i fixed the my build.gradle;
1- you need to create a jar file with dependencies, i found this tutorial :https://www.mkyong.com/gradle/gradle-create-a-jar-file-with-dependencies/
2- added this code to my build.gradle :
/create a single Jar with all dependencies
task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': version,
'Main-Class': 'com.thingworx.sdk.simplething.SimpleThingClient'
}
baseName = project.name + '-all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
3- clean the project with => $ gradle clean
4-Run the Gradle fatJar
task => $ gradle fatJar
voila;