Gradle application plugin | Incorrect 'lib'

2019-07-20 18:53发布

I am trying to use Gradle application plugins as follows:-

build.gradle :-

group 'com.samsoft'
version '1.0-SNAPSHOT'

defaultTasks("clean", "build")

apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'idea'
mainClassName = 'com.samsoft.Main'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

src/main/java.Main.java :-

package com.samsoft;
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}

After running gradle build, we have PRJECT/build/libs & PROJECT/build/scripts folders create and others. The libs has executable jar and its dependencies and scripts has .bat and .sh files to run the application.

PROBLEM

The script file has incorrect classpath as set CLASSPATH=%APP_HOME%\lib\hello-gradle-1.0-SNAPSHOT.jar

's' character is missing from lib which results in Error: Could not find or load main class com.samsoft.Main while trying to run it.

How can I fix this ?

Gradle 3.5 Java 8

1条回答
Fickle 薄情
2楼-- · 2019-07-20 19:34

Scripts in the scripts dir are not meant to be run, there are here just to be included in the final distribution.

If you take a look in the distributions dir, you can see a tar and and zip archive. These will contain both scripts at the root and a lib dir which containing jar files. This is what the CLASSPATH is about :

CLASSPATH=%APP_HOME%\lib\hello-gradle-1.0-SNAPSHOT.jar

%APP_HOME% is the folder where the files have been unzipped / untarred

查看更多
登录 后发表回答