8

我正在使用以下内容:

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

我用 NetBeans 创建了一个 RESTful Web 服务,将它部署在 NetBeans 下,它运行良好。

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

  • Oracle GlassFish 服务器 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但它对我不起作用!!!还有其他建议吗?

4

2 回答 2

5

现在我有了解决方案。我忘记了 JDBC 资源:打开 Glassfish-Server Web 界面并导航到资源 -> JDBC -> JDBC 资源并使用正确的连接池创建一个新资源。如果 Resource 和 Connection Pool 缺失,部署会失败!!!没有 java:app/webservice 对我有用...

于 2013-07-03T10:17:01.677 回答
5

我遇到了同样的问题,它表现为各种奇怪的异常情况,这些异常情况与我的实际问题完全无关。

发生了什么?

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

该怎么办?

解决此问题的一种方法(我使用的方法)是在浏览器中手动进入 GlassFish 管理控制台,localhost:4848然后在左侧的菜单中转到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 将自动完成现有资源。如果它不自动完成,它可能不存在。

于 2015-10-26T21:25:40.030 回答