在Gradle中使用带有JavaExec的Manifest jar时找不到主类 [英] Main class not found when using Manifest jar with JavaExec in Gradle

查看:1167
本文介绍了在Gradle中使用带有JavaExec的Manifest jar时找不到主类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 Jhipster 框架获得了下面的gradle脚本。它用于运行Gatling测试,并且由于Windows上的命令行限制,我尝试使用仅限于清单的jar方法。关于此的详细讨论可以在这里找到 Jhipster问题
但是下面的脚本似乎正确地生成了Manifest jar,但是JavaExec无法找到主要的类,一些指针对此会非常有帮助。错误的控制台日志也在下面



我在gradle论坛上发布了这个这里,但目前还没有运气



apply plugin:'scala'

  sourceSets {
test {
scala {
srcDirs = ['src / test / gatling / simulations']
output.classesDir ='target / test-classes'
}
}
}
任务manifestJar (dependsOn:'compileTestScala',输入:Jar){
dependsOn configurations.runtime
classifier'pathing'
doFirst {
manifest {
//只需要uri对于Windows兼容性
属性'Class-Path':configurations.runtime.files.collect {project.uri(it)} .join('')
}
}
}
任务gatlingRun(dependsOn:'manifestJar',类型:JavaExec){
// dependsOn configurations.runtime
group =gatling

standardInput = System.in

final def sourceSet = sourceSets.test
File configFile =文件('src / test / gatling / conf / gatling.conf')

def String gatlingDataFolder =$ project.rootDir.absolutePath / src / test / gatling / data
def String gatlingReportsFolder =$ project.buildDir.absolutePath / reports / gatling
def String gatlingBodiesFolder =$ project.rootDir.absolutePath / src / test / gatling / bodies
def String gatlingSimulationsFolder =$ project。根目录路径.absolutePath / src / test / gatling / simulations

classpath sourceSet.output + sourceSet.runtimeClasspath + files(src / test / gatling / conf)
classpath sourceSet。输出+文件(manifestJar.archivePath)+文件(src / test / gatling / conf)
// classpath = files(pathingJar.archivePath)
main =io.gatling.app.Gatling

环境GATLING_HOME:''

arg s'-df',gatlingDataFolder
args'-rf',gatlingReportsFolder
args'-bdf',gatlingBodiesFolder
args-sf,gatlingSimulationsFolder
args-rd,

}

控制台日志:

 :compileTestJava UP-TO-DATE 
:compileTestJava(Thread [main,5,main])完成。花了0.973秒。
:compileTestScala(线程[main,5,main])开始。
:compileTestScala
跳过任务':compileTestScala',因为它是最新的(耗时0.325秒)。
:compileTestScala UP-TO-DATE
:compileTestScala(Thread [main,5,main])已完成。花了0.344秒。
:manifestJar(Thread [main,5,main])开始。
:manifestJar
跳过任务':manifestJar',因为它是最新的(花费0.012秒)。
:manifestJar UP-TO-DATE
:manifestJar(Thread [main,5,main])完成。花了0.038秒。
:processTestResources(线程[main,5,main])开始。
:processTestResources
跳过任务':processTestResources',因为它是最新的(花费0.013秒)。
:processTestResources UP-TO-DATE
:processTestResources(Thread [main,5,main])完成。花了0.041秒。
:testClasses(Thread [main,5,main])开始。
:testClasses
跳过任务':testClasses',因为它没有任何操作。
:testClasses UP-TO-DATE
:testClasses(Thread [main,5,main])已完成。花了0.019秒。
:gatlingRun(线程[main,5,main])开始。
:gatlingRun
执行任务':gatlingRun'(最新检查耗时0.001秒),原因是:
任务没有声明任何输出。
启动进程'命令'C:\程序文件\Java\jdk1.8.0_45\bin\java.exe''。工作目录:D:\Projects\jh5命令:C:\程序文件\Java\jdk1.8。
0_45\bin\java.exe -Dfile.encoding = windows-1252 -Duser.country = SG -Duser.language = en -Duser.variant -cp D:\Projects\jh5\target \test-classes; D:\Projects
\jh5\build\resources\test; D:\Projects\jh5\build\libs\jhipster-pathing.jar; D:\Projects\jh5\src\test\gatling\conf io.gatling.app.Gatling -df D:\Projects
\jh5 / src / test / gatling / data - rf D:\Projects\jh5\build / reports / gatling -bdf D:\Projects\jh5/src/test/gatling/ bodies -sf D:\Projects\jh5/src/test/gatling
/ simulations -rd
成功启动进程'command'C:\程序文件\Java\jdk1.8.0_45\bin\java.exe''
错误:可能未找到或加载主类io.gatling.app.Gatling
:gatlingRun FAILED
:gatlingRun(Thread [main,5,main])已完成。花了0.166秒。

失败:构建失败,出现异常。

*出错:
任务'gatlingRun'的执行失败。
>进程'命令'C:\程序文件\Java\jdk1.8.0_45\bin\java.exe''以非零退出值1

完成*尝试:
使用--stacktrace选项运行以获取堆栈跟踪。使用--debug选项运行以获取更多日志输出。

构建失败

总时间:28.134秒
已停止0个编译器守护进程。


解决方案

编辑:
您的清单jar包含错误的类路径。尝试使用 testCompile 文件:

 任务manifestJar(dependsOn:'compileTestScala' ,输入:Jar){
dependsOn configurations.testCompile
archiveName'gatlingBooter.jar'
doFirst {
manifest {
// uri只是Windows兼容需要的
属性'Class-Path':configurations.testCompile.files.collect {project.uri(it)} .join('')
}
}
}






老:

如果清单jar仅工作 java -jar @Deepu,我们应该尝试以下操作:

 任务runJar(dependsOn:jar)<< {
javaexec {main = - jar; args jar.archivePath}
}

至少它看起来不错。




I have the below gradle script from the Jhipster framework. It is used to run Gatling tests and due to the command line limit on windows I have tried using a manifest only jar approach. A detailed discussion regarding this can be found here Jhipster issue But the below script seems to generate the Manifest jar properly but JavaExec is unable to find the main class, some pointer on this would be really helpfull. A console log of error is below as well

I have posted this on the gradle forum here, but no luck so far

apply plugin: 'scala'

sourceSets {
    test {
        scala {
            srcDirs = ['src/test/gatling/simulations']
            output.classesDir = 'target/test-classes'
        }
    }
}
task manifestJar(dependsOn:'compileTestScala',type: Jar) {
    dependsOn configurations.runtime
    classifier 'pathing'
    doFirst {
        manifest {
            // uri is just needed for Windows-compatibility
            attributes 'Class-Path': configurations.runtime.files.collect{ project.uri(it) }.join(' ')
        }
    }
}
task gatlingRun(dependsOn:'manifestJar', type: JavaExec) {
    //dependsOn configurations.runtime
    group = "gatling"

    standardInput = System.in

    final def sourceSet = sourceSets.test
    File configFile = file('src/test/gatling/conf/gatling.conf')

    def String gatlingDataFolder = "$project.rootDir.absolutePath/src/test/gatling/data"
    def String gatlingReportsFolder = "$project.buildDir.absolutePath/reports/gatling"
    def String gatlingBodiesFolder = "$project.rootDir.absolutePath/src/test/gatling/bodies"
    def String gatlingSimulationsFolder = "$project.rootDir.absolutePath/src/test/gatling/simulations"

    //classpath sourceSet.output + sourceSet.runtimeClasspath + files("src/test/gatling/conf")
    classpath sourceSet.output + files(manifestJar.archivePath) + files("src/test/gatling/conf")
    //classpath = files(pathingJar.archivePath)
    main = "io.gatling.app.Gatling"

    environment GATLING_HOME:''

    args '-df', gatlingDataFolder
    args '-rf', gatlingReportsFolder
    args '-bdf', gatlingBodiesFolder
    args "-sf", gatlingSimulationsFolder
    args "-rd", ""

}

Console log:

:compileTestJava UP-TO-DATE
:compileTestJava (Thread[main,5,main]) completed. Took 0.973 secs.
:compileTestScala (Thread[main,5,main]) started.
:compileTestScala
Skipping task ':compileTestScala' as it is up-to-date (took 0.325 secs).
:compileTestScala UP-TO-DATE
:compileTestScala (Thread[main,5,main]) completed. Took 0.344 secs.
:manifestJar (Thread[main,5,main]) started.
:manifestJar
Skipping task ':manifestJar' as it is up-to-date (took 0.012 secs).
:manifestJar UP-TO-DATE
:manifestJar (Thread[main,5,main]) completed. Took 0.038 secs.
:processTestResources (Thread[main,5,main]) started.
:processTestResources
Skipping task ':processTestResources' as it is up-to-date (took 0.013 secs).
:processTestResources UP-TO-DATE
:processTestResources (Thread[main,5,main]) completed. Took 0.041 secs.
:testClasses (Thread[main,5,main]) started.
:testClasses
Skipping task ':testClasses' as it has no actions.
:testClasses UP-TO-DATE
:testClasses (Thread[main,5,main]) completed. Took 0.019 secs.
:gatlingRun (Thread[main,5,main]) started.
:gatlingRun
Executing task ':gatlingRun' (up-to-date check took 0.001 secs) due to:
  Task has not declared any outputs.
Starting process 'command 'C:\Program Files\Java\jdk1.8.0_45\bin\java.exe''. Working directory: D:\Projects\jh5 Command: C:\Program Files\Java\jdk1.8.
0_45\bin\java.exe -Dfile.encoding=windows-1252 -Duser.country=SG -Duser.language=en -Duser.variant -cp D:\Projects\jh5\target\test-classes;D:\Projects
\jh5\build\resources\test;D:\Projects\jh5\build\libs\jhipster-pathing.jar;D:\Projects\jh5\src\test\gatling\conf io.gatling.app.Gatling -df D:\Projects
\jh5/src/test/gatling/data -rf D:\Projects\jh5\build/reports/gatling -bdf D:\Projects\jh5/src/test/gatling/bodies -sf D:\Projects\jh5/src/test/gatling
/simulations -rd
Successfully started process 'command 'C:\Program Files\Java\jdk1.8.0_45\bin\java.exe''
Error: Could not find or load main class io.gatling.app.Gatling
:gatlingRun FAILED
:gatlingRun (Thread[main,5,main]) completed. Took 0.166 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':gatlingRun'.
> Process 'command 'C:\Program Files\Java\jdk1.8.0_45\bin\java.exe'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.

BUILD FAILED

Total time: 28.134 secs
Stopped 0 compiler daemon(s).

解决方案

Edit: Your manifest jar contains the wrong classpath. Try using testCompile files:

task manifestJar(dependsOn:'compileTestScala',type: Jar) {
dependsOn configurations.testCompile
archiveName 'gatlingBooter.jar'
doFirst {
    manifest {
        // uri is just needed for Windows-compatibility
        attributes 'Class-Path': configurations.testCompile.files.collect{ project.uri(it) }.join(' ')
       }
   }
}


OLD:

If the manifest jar only works java -jar @Deepu maybe we should try the following:

task runJar(dependsOn:jar) << {
  javaexec { main="-jar"; args jar.archivePath } 
}

At least it looks good. Will try to test it during the weekend.

References:

这篇关于在Gradle中使用带有JavaExec的Manifest jar时找不到主类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆