1

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

Community
  • 1
  • 1
Paul Verest
  • 60,022
  • 51
  • 208
  • 332
  • As far as I understood the question there's a possibility to start such command with `gradle` but only with invoking system command (starting external process). Have a look here: http://groovy.codehaus.org/Executing+External+Processes+From+Groovy. If that's what You're looking for and You just need to write a task that will do it let me know. Will try to help You. – Opal Apr 18 '14 at 06:35
  • Any solution for now; what I have now is https://github.com/PaulVI/NashornSandbox/issues/1 – Paul Verest Apr 18 '14 at 07:40
  • If it works it seems to be ok. – Opal Apr 18 '14 at 08:14
  • It does not. Let's continue chat on GitHub.. – Paul Verest Apr 18 '14 at 09:28

1 Answers1

3

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'
}
Opal
  • 81,889
  • 28
  • 189
  • 210
  • This works, however without output to console. Spent an hour until checked it is actually running at http://127.0.0.1:1337/calculate?amount=100&percentage=7 – Paul Verest Apr 21 '14 at 03:49
  • For both tasks I see std out. If it doesn't work You can set the stream with `standardOutput System.out`. Not checked but should work fine. Docs: http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.JavaExec.html – Opal Apr 22 '14 at 05:50
  • Well, that seems to be combination of Java, Gradle versions. Now it is OK (Java 8; Gradle 1.11) – Paul Verest Apr 22 '14 at 06:42
  • Maybe. Have exactly same environment (8 and 1.11). – Opal Apr 22 '14 at 06:44