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

时间:2014-12-03 08:47:50

标签: spring jboss gradle

我已经按照本教程(使用基于XML的Spring配置):

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

当我运行Jetty时,它可以工作,我可以看到"你好,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。 观察日志我可以看到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")
//        }
    }
}

但是新的ear文件与旧的相同。

代码(使用原始build.gradle):

1 个答案:

答案 0 :(得分:-1)

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

  • 忘记EAR,使用WAR