TheBoegl / gradle-launch4j

A gradle-plugin to create windows executables with launch4j
Apache License 2.0
305 stars 42 forks source link

how to change jar file location in version 3.0.5 #169

Closed Mason-Chou closed 2 months ago

Mason-Chou commented 7 months ago

I'm trying to change the jar location that the exe is trying to launch. Essentially trying to change it so that the exe looks for the jar in the same directory as it instead of lib/foo.jar.

I've noticed that the jar property got removed, which does what I'm trying to do. Is there an alternative way to do this? This is still possible using the Launch4j software. Maybe I'm not setting the jarTask correctly.

See below for a snippet of my build.gradle

launch4j {
    jarTask = project.getTasksByName("buildJar", false)[0]
    dontWrapJar = true
    outfile = "Foo.exe"
    bundledJrePath = "./jre/${jreImageName}"
    requires64Bit  = true
    icon = "${projectDir}/img/icons/foo.ico"
}

task buildJar(type: Jar) {
    description 'Foo in releaseDir'
    from sourceSets.main.output
    manifest {
        attributes 'Main-Class': project.mainClass
        attributes 'Class-Path': './config/'
    }
    archiveBaseName = 'Foo'
    destinationDirectory = new File(releaseDir)
}
Mason-Chou commented 7 months ago

So I found a workaround on what I'm trying to do and that's to change the libraryDir property to the directory I want the main executable jar to be in. In my case, it would be ''.

Not sure if this is the intended way of configuration, but seems to be able to work on the scenarios I can think of.

New snippet of my build.gradle

launch4j {
    libraryDir = ''
    dontWrapJar = true
    outfile = "Foo.exe"
    bundledJrePath = "./jre/${jreImageName}"
    requires64Bit  = true
    icon = "${projectDir}/img/icons/foo.ico"
}

task buildJar(type: Jar) {
    description 'Foo in releaseDir'
    from sourceSets.main.output
    manifest {
        attributes 'Main-Class': project.mainClass
        attributes 'Class-Path': './config/'
    }
    archiveBaseName = 'Foo'
    destinationDirectory = new File(releaseDir)
}
TheBoegl commented 2 months ago

On the one hand: Your workaround is actually the solution to this issue, since IMHO that is what you were trying to archive. On the other hand, i fixed the issue you indirectly stated in your first message. As of version 3.0.6, you can now provide a task provider instead of immediately resolving the task by changing it to

def buildJar = tasks.register('buildJar', Jar) {
    description 'Foo in releaseDir'
    from sourceSets.main.output
    manifest {
        attributes 'Main-Class': application.mainClass
        attributes 'Class-Path': './config/'
    }
    archiveBaseName = 'Foo'
    destinationDirectory = new File(releaseDir)
}
launch4j {
    jarTask = buildJar
    dontWrapJar = true
    outfile = "Foo.exe"
    bundledJrePath = "./jre/${jreImageName}"
    requires64Bit  = true
}

Please close this issue if I guessed correctly.

Mason-Chou commented 2 months ago

Thanks, that's what I was looking for! Closing this issue now.