【问题标题】:Gradle Build Failed Error: package javax.servlet does not existGradle 构建失败错误:包 javax.servlet 不存在
【发布时间】:2013-03-22 15:39:01
【问题描述】:

我对 gradle 和构建系统还很陌生, 我正在尝试使用 gradle 构建项目,但它找不到我在项目的几个类中使用的 Tomcat 服务器包。

我的构建配置:

apply plugin: 'java'
apply plugin: 'war'

repositories {
   flatDir { dirs "WebContent/WEB-INF/lib" }
   mavenCentral()
}

dependencies {
    compile group: 'com.orientechnologies', name: 'orient-commons', version: '1.3.0'
    compile group: 'com.orientechnologies', name: 'orientdb-client', version: '1.3.0'
    compile group: 'com.orientechnologies', name: 'orientdb-core', version: '1.3.0'
    compile group: 'com.orientechnologies', name: 'orientdb-graphdb', version: '1.3.0'
    compile group: 'com.orientechnologies', name: 'orientdb-enterprise', version: '1.3.0'
    compile group: 'com.tinkerpop.blueprints', name: 'blueprints-core', version: '2.3.0'
    compile group: 'com.tinkerpop.blueprints', name: 'blueprints-orient-graph', version: '2.3.0'
    compile group: 'com.tinkerpop', name: 'pipes', version: '2.3.0'
    compile group: 'com.tinkerpop.gremlin', name: 'gremlin-java', version: '2.3.0'
    compile group: 'com.tinkerpop.gremlin', name: 'gremlin-groovy', version: '2.3.0'

    testCompile group: 'junit', name: 'junit', version: '4.+'
    testCompile group: 'org.mockito', name: 'mockito-all', version: '1.9.5'

}
sourceSets {
    main {
        java {
            srcDir 'src'
        }
    }
    test {
        java {
            srcDir 'test'
        }
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.3'
}
war {
    from 'WebContent'
}

当我启动 Gradle Task - Build 时发生错误:

OrientDBFilter.java:6: error: package javax.servlet does not exist
import javax.servlet.FilterChain;
OrientDBFilter.java:5: error: package javax.servlet does not exist
import javax.servlet.Filter;

....

【问题讨论】:

    标签: build gradle


    【解决方案1】:

    通常你会使用providedCompile。比如:

    providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.0.1'
    

    然后您的应用将编译,但 gradle 不会在最终的 war 文件中包含 servlet api。

    【讨论】:

    • 为什么不能与compileOnly 组一起编译?
    【解决方案2】:

    我遇到了同样的问题,providedCompile 的解决方案不起作用,但只是
    compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.0.1' 起作用了。

    如果有人遇到同样的问题,我只是想分享一下。

    【讨论】:

      【解决方案3】:

      我遇到了同样的问题,这条线有效

      compileOnly group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'
      

      【讨论】:

        猜你喜欢
        • 2013-04-22
        • 1970-01-01
        • 2015-05-10
        • 1970-01-01
        • 2012-02-29
        • 2016-03-07
        • 1970-01-01
        相关资源
        最近更新 更多