Gradle application plugin | Incorrect 'lib' folder in generated script

爷,独闯天下 提交于 2020-01-03 16:49:46

问题


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:


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



来源:https://stackoverflow.com/questions/43344723/gradle-application-plugin-incorrect-lib-folder-in-generated-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!