如何在Tomee Web服务器上运行gradle Web项目?

时间:2019-07-01 16:52:47

标签: gradle java-ee netbeans tomee

我正在一个网站上。这是我的gradle文件:

buildscript{
    repositories{
        jcenter()
    }
    dependencies{
        classpath("org.hibernate:hibernate-gradle-plugin:5.4.2.Final")
        classpath("org.apache.tomee.gradle:tomee-embedded:8.0.0-M3")
    }
}

plugins{
    id("java");
    id("war")
    id("org.hibernate.gradle.tools") version ("1.2.5")
}

apply plugin: "org.hibernate.orm"
apply plugin: "org.apache.tomee.tomee-embedded"

allprojects{
    repositories{
        jcenter()
    }
}
version = "1.0"
sourceCompatibility = "1.8"
targetCompatibility = "1.8"

tasks.withType(JavaCompile){
    options.encoding = "UTF-8"
}

dependencies{
    def jsfVersion = "2.2.19"
    def hibernateValidatorVersion = "6.0.2.Final"
    def hibernateCore = "5.4.3.Final"
    def tomcatVersion = "9.0.21"


    providedCompile("javax:javaee-api:8.0.1")
    providedCompile("javax.servlet:servlet-api:2.5")
    providedCompile("org.apache.tomee:javaee-api:8.0-1")

    // Hibernate Components
    compile("org.hibernate:hibernate-core:$hibernateCore")
    compile("org.hibernate:hibernate-entitymanager:$hibernateCore")
    compile("org.hibernate.validator:hibernate-validator:$hibernateValidatorVersion")
    compile("org.hibernate.validator:hibernate-validator-annotation-processor:$hibernateValidatorVersion")
    compile("org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final")

    // JSF Components
    compile("com.sun.faces:jsf-api:$jsfVersion")
    compile("com.sun.faces:jsf-impl:$jsfVersion")

    // Primefaces Components
    compile("org.primefaces:primefaces:6.0")
    compile("javax.validation:validation-api:2.0.1.Final")

    // Log4j Components
    compile("log4j:log4j:1.2.17")

    testCompile("junit:junit:4.12")
}

war{
    from("src/main/webapp/")
    webXml = file("src/main/webapp/WEB-INF/Web.xml")
}

hibernate{
    enhance{
        enableLazyInitialization    = true
        enableDirtyTracking         = true
        enableExtendedEnhancement   = false
    }
}

我使用 tomee-embedded 插件,但是无法在netbeans中运行我的项目。相反,我使用命令行。但是,当我用 gradle tomee-embedded -i 运行gradle时,出现此错误:

    Execution failed for task ':tomee-embedded'.
> Could not resolve all files for configuration ':tomee-embedded'.
   > Could not find org.apache.tomee.patch:bval-jsr:2.0.2-69c36fa8-1.
     Searched in the following locations:
       - file:/C:/Users/Arash/.m2/repository/org/apache/tomee/patch/bval-jsr/2.0.2-69c36fa8-1/bval-jsr-2.0.2-69c36fa8-1.pom
       - file:/C:/Users/Arash/.m2/repository/org/apache/tomee/patch/bval-jsr/2.0.2-69c36fa8-1/bval-jsr-2.0.2-69c36fa8-1.jar
       - https://repo.maven.apache.org/maven2/org/apache/tomee/patch/bval-jsr/2.0.2-69c36fa8-1/bval-jsr-2.0.2-69c36fa8-1.pom
       - https://repo.maven.apache.org/maven2/org/apache/tomee/patch/bval-jsr/2.0.2-69c36fa8-1/bval-jsr-2.0.2-69c36fa8-1.jar
       - https://jcenter.bintray.com/org/apache/tomee/patch/bval-jsr/2.0.2-69c36fa8-1/bval-jsr-2.0.2-69c36fa8-1.pom
       - https://jcenter.bintray.com/org/apache/tomee/patch/bval-jsr/2.0.2-69c36fa8-1/bval-jsr-2.0.2-69c36fa8-1.jar
     Required by:
         project : > org.apache.tomee:tomee-embedded:8.0.0-M3 > org.apache.tomee:openejb-core:8.0.0-M3

我试图这样配置Tomee:

def tomeeEmbedded = extensions.getByName('tomee-embedded')
tomeeEmbedded.skipDefaultRepository  = true

但是我又得到了错误。有什么问题?以及如何在Netbeans中运行我的项目。

Web服务器:Apache TomEE Plus v8.0.0-M1

IDE:Apache Netbeans 11

版本版本:5.4.1

2 个答案:

答案 0 :(得分:1)

M3 bval依赖关系是错误的,请尝试从tomee嵌入中排除它,并用最后一个oeg.apache.bval:bval-jsr一个代替

答案 1 :(得分:0)

做什么 步骤1:gradlew build 第二步:gradle tomee-embedded -i

为什么 创建build.gradle文件后,第一个任务是运行

gradlew build命令,以便它可以下载所需的依赖项和插件,因此 请运行gradlew build,然后运行您的TomEE命令。

这应该可行,

如果使用windows,则命令可能会变化gradlew.bat build;对于Linux,命令将与上述gradlew build相同