【问题标题】:Generating EAR with Gradle (Spring application at JBoss)使用 Gradle 生成 EAR(JBoss 的 Spring 应用程序)
【发布时间】:2014-12-03 08:47:50
【问题描述】:

我已遵循本教程(使用基于 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 = ''

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

你知道怎么解决吗?

更糟糕的是,当我尝试在服务器 JBoss-5.1.0.GA 上部署相同的 ear 文件时,应用程序永远不会部署。服务器日志:

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")
//        }
    }
}

但是新的ear文件和旧的有同样的问题。

代码(带有原始 build.gradle):

【问题讨论】:

  • 看来ear文件也应该配置得当。你完成了吗?你看到了吗:gradle.org/docs/current/userguide/ear_plugin.html
  • 我尝试根据文档配置 ear 文件(参见上面的“更新”)。但这并不能解决问题。 @Opal
  • 你有这个项目托管在公共 repo 上吗?
  • 教程的代码是一样的(改“build.gradle”来生成EAR):ZIP,GitHub(也许我有JBoss的问题而不是Gradle)@Opal
  • 好的,@JavierCasas。也许我稍后会看看。

标签: spring jboss gradle


【解决方案1】:

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

  • 忘记 EAR,使用 WAR

【讨论】:

    猜你喜欢
    • 2020-11-10
    • 1970-01-01
    • 1970-01-01
    • 2017-01-11
    • 1970-01-01
    • 2015-01-12
    • 1970-01-01
    • 2017-01-22
    相关资源
    最近更新 更多