部署时出现Glassfish服务器错误.war:部署期间出错:准备应用程序时出现异常:资源无效

时间:2013-06-19 16:49:42

标签: java deployment web glassfish war

我使用以下内容:

  • NetBeans IDE 7.3(Build 201306052037)
  • Java:1.7.0_17; Java HotSpot(TM)64位服务器VM 23.7-b01
  • NetBeans集成的GlassFish Server开源版3.1.2.2(版本5)

我使用NetBeans创建了一个RESTful Webservice,在NetBeans下部署它并且工作正常。

所以我将生成的.war文件复制到另一台使用:

的机器上
  • Oracle GlassFish Server 3.1.2.2
  • java版“1.7.0_21”Java HotSpot(TM)客户端VM(版本23.21-b01,混合模式)

当我想部署.war文件时,我收到此错误:

远程故障:部署期间出错:准备应用程序时出现异常:资源无效:webservice__pm。有关更多详细信息,请参阅server.log。 命令部署失败。

这是我的glassfish-resources.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
    <jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="webservice" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
        <property name="portNumber" value="3306"/>
        <property name="databaseName" value="webservice"/>
        <property name="User" value="webservice"/>
        <property name="Password" value="webservice"/>
        <property name="URL" value="jdbc:mysql://localhost:3306/webservice?zeroDateTimeBehavior=convertToNull"/>
        <property name="Url" value="jdbc:mysql://localhost:3306/webservice?zeroDateTimeBehavior=convertToNull"/>
        <property name="driverClass" value="com.mysql.jdbc.Driver"/>
    </jdbc-connection-pool>
    <jdbc-resource enabled="true" jndi-name="webservice" object-type="user" pool-name="webservice"/>
</resources>

这是我的persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="DatensammlerPU" transaction-type="JTA">
    <jta-data-source>webservice</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
    </properties>
  </persistence-unit>
</persistence>

以下是来自 server.log 的错误消息:

[#|2013-06-19T17:52:55.064+0200|SEVERE|oracle-glassfish3.1.2|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=68;_ThreadName=Thread-2;|Exception while invoking class org.glassfish.persistence.jpa.JPADeployer prepare method|#]

[#|2013-06-19T17:52:55.064+0200|SEVERE|oracle-glassfish3.1.2|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=68;_ThreadName=Thread-2;|Exception while preparing the app|#]

[#|2013-06-19T17:52:55.065+0200|SEVERE|oracle-glassfish3.1.2|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=68;_ThreadName=Thread-2;|Invalid resource : webservice__pm
java.lang.RuntimeException: Invalid resource : webservice__pm
        at com.sun.enterprise.connectors.ConnectorRuntime.lookupDataSourceInDAS(ConnectorRuntime.java:540)
        at com.sun.enterprise.connectors.ConnectorRuntime.lookupPMResource(ConnectorRuntime.java:469)
        at org.glassfish.persistence.common.PersistenceHelper.lookupPMResource(PersistenceHelper.java:63)
        at org.glassfish.persistence.jpa.ProviderContainerContractInfoBase.lookupDataSource(ProviderContainerContractInfoBase.java:71)
        at org.glassfish.persistence.jpa.PersistenceUnitInfoImpl.<init>(PersistenceUnitInfoImpl.java:108)
        at org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:155)
        at org.glassfish.persistence.jpa.PersistenceUnitLoader.<init>(PersistenceUnitLoader.java:120)
        at org.glassfish.persistence.jpa.JPADeployer$1.visitPUD(JPADeployer.java:224)
        at org.glassfish.persistence.jpa.JPADeployer$PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:495)
        at org.glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:233)
        at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:168)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:871)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:410)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
        at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
        at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
        at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
        at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
        at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
        at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
        at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
        at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
        at java.lang.Thread.run(Thread.java:722)
Caused by: com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: Invalid resource : webservice__pm
        at com.sun.enterprise.connectors.service.ConnectorResourceAdminServiceImpl$MyDataSource.validateResource(ConnectorResourceAdminServiceImpl.java:274)
        at com.sun.enterprise.connectors.service.ConnectorResourceAdminServiceImpl$MyDataSource.setResourceInfo(ConnectorResourceAdminServiceImpl.java:255)
        at com.sun.enterprise.connectors.service.ConnectorResourceAdminServiceImpl.lookupDataSourceInDAS(ConnectorResourceAdminServiceImpl.java:245)
        at com.sun.enterprise.connectors.ConnectorRuntime.lookupDataSourceInDAS(ConnectorRuntime.java:538)
        ... 40 more
|#]

[#|2013-06-19T17:52:55.070+0200|WARNING|oracle-glassfish3.1.2|javax.enterprise.resource.resourceadapter.com.sun.enterprise.resource.deployer|_ThreadID=111;_ThreadName=Thread-2;|The log message is empty or null. Please log an issue against the component in the logger field.|#]

[#|2013-06-19T17:52:55.082+0200|WARNING|oracle-glassfish3.1.2|javax.enterprise.resource.resourceadapter.com.sun.enterprise.resource.deployer|_ThreadID=111;_ThreadName=Thread-2;|The log message is empty or null. Please log an issue against the component in the logger field.|#]

[#|2013-06-19T17:52:55.083+0200|WARNING|oracle-glassfish3.1.2|javax.enterprise.resource.resourceadapter.com.sun.enterprise.resource.deployer|_ThreadID=111;_ThreadName=Thread-2;|The log message is empty or null. Please log an issue against the component in the logger field.|#]

[#|2013-06-19T17:52:55.083+0200|SEVERE|oracle-glassfish3.1.2|javax.enterprise.system.tools.admin.org.glassfish.deployment.admin|_ThreadID=68;_ThreadName=Thread-2;|Exception while preparing the app : Invalid resource : webservice__pm
com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: Invalid resource : webservice__pm
        at com.sun.enterprise.connectors.service.ConnectorResourceAdminServiceImpl$MyDataSource.validateResource(ConnectorResourceAdminServiceImpl.java:274)
        at com.sun.enterprise.connectors.service.ConnectorResourceAdminServiceImpl$MyDataSource.setResourceInfo(ConnectorResourceAdminServiceImpl.java:255)
        at com.sun.enterprise.connectors.service.ConnectorResourceAdminServiceImpl.lookupDataSourceInDAS(ConnectorResourceAdminServiceImpl.java:245)
        at com.sun.enterprise.connectors.ConnectorRuntime.lookupDataSourceInDAS(ConnectorRuntime.java:538)
        at com.sun.enterprise.connectors.ConnectorRuntime.lookupPMResource(ConnectorRuntime.java:469)
        at org.glassfish.persistence.common.PersistenceHelper.lookupPMResource(PersistenceHelper.java:63)
        at org.glassfish.persistence.jpa.ProviderContainerContractInfoBase.lookupDataSource(ProviderContainerContractInfoBase.java:71)
        at org.glassfish.persistence.jpa.PersistenceUnitInfoImpl.<init>(PersistenceUnitInfoImpl.java:108)
        at org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:155)
        at org.glassfish.persistence.jpa.PersistenceUnitLoader.<init>(PersistenceUnitLoader.java:120)
        at org.glassfish.persistence.jpa.JPADeployer$1.visitPUD(JPADeployer.java:224)
        at org.glassfish.persistence.jpa.JPADeployer$PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:495)
        at org.glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:233)
        at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:168)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:871)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:410)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
        at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
        at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
        at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
        at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
        at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
        at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
        at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
        at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
        at java.lang.Thread.run(Thread.java:722)

我读了很多,我应该使用 java:app / webservice ,但它对我不起作用! 还有其他建议吗?

2 个答案:

答案 0 :(得分:5)

现在我有了解决方案。 我忘记了JDBC资源: 打开Glassfish-Server Web界面并导航到Resources - &gt; JDBC - &gt; JDBC资源并使用正确的连接池创建一个新的资源。如果缺少资源和连接池,部署将失败! 它适用于没有java的应用程序:app / webservice ...

答案 1 :(得分:4)

我有同样的问题,它表现在各种奇怪的异常情况中,与我的实际问题完全无关。

发生了什么事?

由于某些原因,尚未在GlassFish中创建jdbc/[your resource name]的资源,它会向您抛出jdbc/[your resource name]__[generated thing, like "pm"]作为来源。

怎么做?

解决此问题的一种方法(我使用的方法)是在localhost:4848的浏览器中手动进入GlassFish管理控制台,然后在左侧菜单中转到Resources并按照树在它里面:JDBC > JDBC resources。在JDBC Resources标签中,您可以创建新资源并将其命名为jdbc/[your resource name]__[generated thing, like "pm"]不是必需的。

但是现在不能正常工作我该做什么?!

这正是发生在我身上的事情,这就是我开始得到奇怪异常的地方,比如它突然找不到我的数据库驱动程序,即使我在我的依赖文件夹中盯着它。

我该如何解决呢?

重新启动NetBeans,刷新GlassFish并在必要时重新启动它。运行项目,它应该部署。

(我从一个关于MDB的例外中找到了我的问题的来源,当我删除它时,它突然使用我添加的资源,然后我可以将它重命名为我想要的任何东西,只要有是GlassFish中的匹配资源。您可能需要在GlassFish中查看MDB JNDI设置并手动为它们创建资源)

额外提示:

当您编写<jta-data-source>标记时,NetBeans将自动填充现有资源。如果它没有自动完成,则可能不存在。