Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java LibGDX Gradle:Export.jar不带打包资源_Java_Gradle_Libgdx_Export_Desktop - Fatal编程技术网

Java LibGDX Gradle:Export.jar不带打包资源

Java LibGDX Gradle:Export.jar不带打包资源,java,gradle,libgdx,export,desktop,Java,Gradle,Libgdx,Export,Desktop,桌面项目的build.gradle文件如下所示 apply plugin: "java" sourceCompatibility = 1.8 sourceSets.main.java.srcDirs = [ "src/" ] sourceSets.main.resources.srcDirs = [ "../core/assets" ] project.ext.mainClassName = "com.rin.deskto

桌面项目的
build.gradle
文件如下所示

apply plugin: "java"

sourceCompatibility = 1.8
sourceSets.main.java.srcDirs = [ "src/" ]
sourceSets.main.resources.srcDirs = [ "../core/assets" ]

project.ext.mainClassName = "com.rin.desktop.ClientLauncher"
project.ext.assetsDir = new File("../core/assets");
project.buildDir = '/Users/lukassongajlo/Dropbox/Elementar/Implementation/Test Versions/Client Version'

task run(dependsOn: classes, type: JavaExec) {
    main = project.mainClassName
    classpath = sourceSets.main.runtimeClasspath
    standardInput = System.in
    workingDir = project.assetsDir
    ignoreExitValue = true
}

task debug(dependsOn: classes, type: JavaExec) {
    main = project.mainClassName
    classpath = sourceSets.main.runtimeClasspath
    standardInput = System.in
    workingDir = project.assetsDir
    ignoreExitValue = true
    debug = true
}

task dist(type: Jar) {
    manifest {
        attributes 'Main-Class': project.mainClassName
    }
    dependsOn configurations.runtimeClasspath
    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
    with jar

}


dist.dependsOn classes

eclipse {
    project {
        name = appName + "-desktop"
        linkedResource name: 'assets', type: '2', location: 'PARENT-1-PROJECT_LOC/core/assets'
    }
}

task afterEclipseImport(description: "Post processing after project generation", group: "IDE") {
  doLast {
    def classpath = new XmlParser().parse(file(".classpath"))
    new Node(classpath, "classpathentry", [ kind: 'src', path: 'assets' ]);
    def writer = new FileWriter(file(".classpath"))
    def printer = new XmlNodePrinter(new PrintWriter(writer))
    printer.setPreserveWhitespace(true)
    printer.print(classpath)
  }
}

。。。运行
gradlew desktop:dist
后,我得到以下文件夹结构

[问题]:
libs
中的是一个独立的.jar(见下图),因此不需要其他资源。有没有办法只获取这个.jar文件而不获取整个文件夹结构?提前表示感谢:)


这些构建目录是创建jar文件所必需的,因此您不能完全没有它们。但舒尔可以在构建完成后将其删除

您可以这样尝试:

// ...

// your 'dist' task stays untouched
task dist(type: Jar) {
    manifest {
        attributes 'Main-Class': project.mainClassName
    }
    dependsOn configurations.runtimeClasspath
    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
    with jar
}

task deleteUnusedBuildDirs(type: Delete) {
    delete 'build/classes';
    delete 'build/generated';
    delete 'build/resources';
    delete 'build/tmp';
}

dist.finalizedBy deleteUnusedBuildDirs

//...