Running an executable JAR from a remote maven repo

Hello All,

I’m trying to create a very simple script to execute a JAR file retrieved from a remote repository, e.g. “java -jar myfile.jar”. The script below works but requires me to inspect the MANIFEST.MF to get the Main-Class, which defeats the purpose.

Can someone please help me?

Thanks!

–john

apply plugin: 'java'

repositories {
    maven {
        url 'http://artifacts.unidata.ucar.edu/content/repositories/unidata-releases'
    }
}

dependencies {
    runtime "edu.ucar:toolsUI:4.6.4"
}

//goal is to be able to execute equivalent of "java -jar toolsUI-4.6.4.jar"
task runToolsUI(type: JavaExec) {
    main = "ucar.nc2.ui.ToolsUI"
    classpath = sourceSets.main.runtimeClasspath
}

It might work using jvmArgs (not 100% sure but worth a try)

configurations {
    toolsUi
}
dependencies {
    toolsUi "edu.ucar:toolsUI:4.6.4"
}
task runToolsUI(type: JavaExec) {
    jvmArgs ['-jar', configurations.toolsUi.singleFile.absolutePath]
}

Thanks for the suggestion, but it still seems to require the “main” property using the below:

jvmArgs = ['-jar', configurations.toolsUIRuntime.singleFile.absolutePath]

–john

Hmm… That’s what I was worried about. Perhaps you could roll your own task using JavaExec.java as a reference.

Eg

task runToolsUI << {
   ExecActionFactory factory = gradle.getService(ExecActionFactory)
   JavaExecAction action = factory.newJavaExecAction() 
   action.setJvmArgs ['-jar', configurations.toolsUi.singleFile.absolutePath]
   action.execute()
} 

*** edit ***
This aporoach won’t work as the main class requirement is coded in the base class of DefaultJavaExecAction. You may need to roll your own Exec task