spring - 使用Gradle生成EAR(JBoss的Spring应用程序)

标签 spring jboss gradle

我遵循了本教程(使用基于XML的Spring配置):

http://codetutr.com/2013/03/24/simple-spring-mvc-web-application-using-gradle/

当我运行Jetty时,它可以工作,并且可以看到“Hello,CodeTutr!”。在http://localhost:8080/home

然后我修改build.gradle来生成一个ear文件:

apply plugin: 'ear'
apply plugin: 'war'
apply plugin: 'jetty'
apply plugin: 'eclipse-wtp'

repositories {
   mavenCentral()
}

dependencies {
   compile 'org.springframework:spring-webmvc:3.2.2.RELEASE'
   compile 'javax.servlet:javax.servlet-api:3.0.1'
   runtime 'javax.servlet:jstl:1.1.2'
   deploy files(war)
}

/* Change context path (base url). otherwise defaults to name of project */
jettyRunWar.contextPath = ''

耳朵文件的生成没有问题,但是当我使用本地JBoss-4.0.4.GA部署耳朵文件时,会看到“你好,$ {name}!”。在http://localhost:8080/spring-mvc/home
查看日志,我可以看到Controller在每次重新加载URL时都在运行,但是它永远不会替换$ {name}。

你知道如何解决吗?

甚至更糟的是,当我尝试在服务器JBoss-5.1.0.GA上部署相同的Ear文件时,从不部署应用程序。 Server.log:
2014-12-03 09:05:03,668 WARN  [org.jboss.util.xml.JBossEntityResolver] (HDScanner) Trying to resolve systemId as a non-file URL: http://java.sun.com/xml/ns/javaee/application_6.xsd
2014-12-03 09:05:04,932 WARN  [org.jboss.util.xml.JBossEntityResolver] (HDScanner) Trying to resolve systemId as a non-file URL: http://java.sun.com/xml/ns/javaee
2014-12-03 09:05:13,001 WARN  [org.jboss.system.server.profileservice.hotdeploy.HDScanner] (HDScanner) Scan failed
org.jboss.deployers.spi.DeploymentException: Exception determining structure: AbstractVFSDeployment(spring-mvc.ear)
    at org.jboss.deployers.spi.DeploymentException.rethrowAsDeploymentException(DeploymentException.java:49)
    at org.jboss.deployers.structure.spi.helpers.AbstractStructuralDeployers.determineStructure(AbstractStructuralDeployers.java:85)
    at org.jboss.deployers.plugins.main.MainDeployerImpl.determineStructure(MainDeployerImpl.java:1004)
    at org.jboss.deployers.plugins.main.MainDeployerImpl.determineDeploymentContext(MainDeployerImpl.java:440)
    at org.jboss.deployers.plugins.main.MainDeployerImpl.addDeployment(MainDeployerImpl.java:390)
    at org.jboss.deployers.plugins.main.MainDeployerImpl.addDeployment(MainDeployerImpl.java:300)
    at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.addDeployment(MainDeployerAdapter.java:86)
    at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:344)
    at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScanner.java:255)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
    at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.RuntimeException: Error determining structure: spring-mvc.ear
    at org.jboss.deployment.EARStructure.determineStructure(EARStructure.java:293)
    at org.jboss.deployers.vfs.plugins.structure.StructureDeployerWrapper.determineStructure(StructureDeployerWrapper.java:73)
    at org.jboss.deployers.vfs.plugins.structure.VFSStructuralDeployersImpl.doDetermineStructure(VFSStructuralDeployersImpl.java:196)
    at org.jboss.deployers.vfs.plugins.structure.VFSStructuralDeployersImpl.determineStructure(VFSStructuralDeployersImpl.java:221)
    at org.jboss.deployers.structure.spi.helpers.AbstractStructuralDeployers.determineStructure(AbstractStructuralDeployers.java:77)
    ... 16 more
Caused by: org.jboss.xb.binding.JBossXBException: Failed to parse source: Failed to parse schema for nsURI=http://java.sun.com/xml/ns/javaee, baseURI=null, schemaLocation=http://java.sun.com/xml/ns/javaee/application_6.xsd
    at org.jboss.xb.binding.parser.sax.SaxJBossXBParser.parse(SaxJBossXBParser.java:203)
    at org.jboss.xb.binding.parser.sax.SaxJBossXBParser.parse(SaxJBossXBParser.java:183)
    at org.jboss.xb.binding.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:161)
    at org.jboss.deployment.EARStructure.determineStructure(EARStructure.java:160)
    ... 20 more
Caused by: org.jboss.xb.binding.JBossXBRuntimeException: Failed to parse schema for nsURI=http://java.sun.com/xml/ns/javaee, baseURI=null, schemaLocation=http://java.sun.com/xml/ns/javaee/application_6.xsd
    at org.jboss.xb.binding.resolver.AbstractMutableSchemaResolver.resolve(AbstractMutableSchemaResolver.java:293)
    at org.jboss.xb.binding.sunday.unmarshalling.SundayContentHandler.startElement(SundayContentHandler.java:274)
    at org.jboss.xb.binding.parser.sax.SaxJBossXBParser$DelegatingContentHandler.startElement(SaxJBossXBParser.java:401)
    at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
    at org.apache.xerces.xinclude.XIncludeHandler.startElement(Unknown Source)
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at org.jboss.xb.binding.parser.sax.SaxJBossXBParser.parse(SaxJBossXBParser.java:199)
    ... 23 more
Caused by: org.jboss.xb.binding.JBossXBRuntimeException: -1:-1 31:3 The declaration for the entity "HTML.Version" must end with '>'.
    at org.jboss.xb.binding.sunday.unmarshalling.XsdBinderTerminatingErrorHandler.handleError(XsdBinderTerminatingErrorHandler.java:40)
    at org.apache.xerces.impl.xs.XMLSchemaLoader.reportDOMFatalError(Unknown Source)
    at org.apache.xerces.impl.xs.XSLoaderImpl.load(Unknown Source)
    at org.jboss.xb.binding.Util.loadSchema(Util.java:395)
    at org.jboss.xb.binding.sunday.unmarshalling.XsdBinder.bind(XsdBinder.java:176)
    at org.jboss.xb.binding.sunday.unmarshalling.XsdBinder.bind(XsdBinder.java:147)
    at org.jboss.xb.binding.resolver.AbstractMutableSchemaResolver.resolve(AbstractMutableSchemaResolver.java:285)
    ... 37 more

你知道如何解决吗?

谢谢

更新:

war文件(在ear文件旁边生成)已部署在Tomcat-6.0.39上,并且工作正常。

阅读此“http://www.gradle.org/docs/current/userguide/ear_plugin.html”,我修改了build.gradle:
apply plugin: 'ear'
apply plugin: 'war'
apply plugin: 'jetty'
apply plugin: 'eclipse-wtp'

repositories {
   mavenCentral()
}

dependencies {
   compile 'org.springframework:spring-webmvc:3.2.2.RELEASE'
   compile 'javax.servlet:javax.servlet-api:3.0.1'
   runtime 'javax.servlet:jstl:1.1.2'
   deploy files(war)   

    // The following dependencies will become ear libs and will
    // be placed in a dir configured via the libDirName property
    earlib group: 'log4j', name: 'log4j', version: '1.2.15', ext: 'jar'
}

/* Change context path (base url). otherwise defaults to name of project */
jettyRunWar.contextPath = ''


ear {
    appDirName 'src/main/webapp'  // use application metadata found in this folder
    // put dependent libraries into APP-INF/lib inside the generated EAR
    libDirName 'WEB-INF/lib'
    deploymentDescriptor {  // custom entries for application.xml:
//      fileName = "application.xml"  // same as the default value
//      version = "6"  // same as the default value
        applicationName = "spring-mvc"
        initializeInOrder = true
        displayName = "spring-mvc"  // defaults to project.name
        // defaults to project.description if not set
        description = "spring-mvc"
//      libraryDirectory = "WEB-INF/lib"  // not needed, above libDirName setting does this
//      module("spring-mvc.jar", "java")  // won't deploy as my.jar isn't deploy dependency
      webModule("spring-mvc.war", "/")  // won't deploy as my.war isn't deploy dependency
//        securityRole "admin"
//        securityRole "superadmin"
//        withXml { provider -> // add a custom node to the XML
//            provider.asNode().appendNode("data-source", "my/data/source")
//        }
    }
}

但是,新的耳朵文件与旧的文件具有相同的问题。

代码(带有原始的build.gradle):
  • ZIP
  • GitHub
  • 最佳答案

    它不是“使用Gradle生成EAR ...”的解决方案,而是针对我的情况的解决方案:

  • 忘记EAR,使用WAR
  • 关于spring - 使用Gradle生成EAR(JBoss的Spring应用程序),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27267182/

    相关文章:

    java - Wildfly 8 : Not able to deploy Jolokia running at different port w. r.t同一IP下的其他应用程序

    java - 在 JBOSS 5.1.1 中获取部署异常

    安卓工作室 :JNI DETECTED ERROR IN APPLICATION: native code passing in reference to invalid local reference: 0x200001

    android - 没有与Android模拟器兼容的拆分APK

    java - CloudFoundry 上的 MySql 经常因查询执行中断而失败;

    java - 如何在不继承 'spring-boot-starter-parent' 模块的情况下测试我的 Spring-Boot 应用程序?

    java - 在 Eclipse Luna 中配置 jboss-eap-6.4 服务器时分配正确的主目录时出错

    android - 无法访问 'java.lang.Object' 这是...的父类(super class)型检查您的模块类路径是否存在缺失或冲突的依赖项

    java - 使用 JpaRepository 查询获取值的出现

    java - 如何动态生成bean列表