Question

Can there be gradle/groovy code analog for launch of java -Djava.library.path=lib -jar lib/avatar-js.jar helloWorld.js, that is lanching .js file with Java 8 and passing some libs

or using defined dependencies

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'

repositories {
    maven {
        url "https://maven.java.net/content/repositories/public/"
    }
}

dependencies {
    compile "com.oracle:avatar-js:0.10.25-SNAPSHOT"
    compile "com.oracle:libavatar-js-win-x64:0.10.25-SNAPSHOT"
}

task copyLibs(type: Copy) {
    from configurations.compile
    into 'lib'
}

sourceSets {
    main {
        java {
            srcDir 'src'
        }
        resources {
            srcDir 'src '
        }
    }
}

The only related docs I found (Build and run a jar inside of a Gradle task) is line from Chapter 45. The Application Plugin

 startScripts   jar     CreateStartScripts  Creates OS specific scripts to run the project as a JVM application.

Application plugins is Java dependent, no way to define task for JavaScript or C/C++ CreateStartScripts requires String mainClassName (not file to run)

Sources at https://github.com/PaulVI/NashornSandbox

Was it helpful?

Solution

Here You have 2 gradle tasks that will run the server:

task runHelloWorld(type: Exec) {
    commandLine 'java', '-Djava.library.path=lib', '-jar', 'lib/avatar-js.jar', 'helloWorld.js'
}

task runHelloWorld2(type: JavaExec) {
    args 'helloWorld.js'
    main 'com.oracle.avatar.js.Server'
    systemProperties 'java.library.path':'lib'
    classpath 'lib/avatar-js.jar'
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top