0

我的项目包含一个jar和一个war模块。该jar模块包含源集maingenerated.

我的jar模块gradle.build定义了源集,如下所示:

sourceSets {
    generated
    main {
        compileClasspath += sourceSets.generated.output  // adds the sourceSet to the compileClassPath
        runtimeClasspath += sourceSets.generated.output  // adds the sourceSet to the runtimeClasspath
    }
}

并将两个源集的输出放入 jar 中。

jar {
    from sourceSets.generated.output
    from sourceSets.main.output
}

在我的war模块中,我想使用 Gretty 在构建中运行它。该build.gradle文件看起来像这样。

apply plugin: 'war'
apply from: "${rootDir}/gradle/gretty.gradle"

gretty {
    // supported values:
    // 'jetty7', 'jetty8', 'jetty9', 'tomcat7', 'tomcat8'
    servletContainer = 'tomcat8'

    httpPort = 8081
    contextPath = '/wbc'
    realm 'wbc-realm'
    realmConfigFile 'tomcat-users.xml'
}

dependencies {
    compile project(':interfaces')

    compile "org.atmosphere:atmosphere-runtime:${atmosphereVersion}"
    compile "org.springframework:spring-web:${springVersion}"
    compile "javax.servlet:javax.servlet-api:${servletVersion}"

    runtime "org.slf4j:slf4j-log4j12:${slf4jVersion}"
    runtime "log4j:log4j:1.2.17"
}

每当我使用gradle --daemon clean appRunGretty 启动 Gretty 时,由于ClassNotFoundException. 该类位于我的模块的generated源集中。jar如何告诉 gretty 将其添加到类路径中?

4

1 回答 1

0

尝试将生成的输出目录添加到 gretty classPath:

gretty {
  ...
  sourceSets.generated.output.each { classPath it }
}
于 2016-07-12T10:51:41.197 回答