Glassfish Server Error when deploy .war: Error occurred during deployment: Exception while preparing the app : Invalid resource
Solution 1
Now I have the solution. I forgot the JDBC Resource: Open the Glassfish-Server Webinterface and navigate to Resources -> JDBC -> JDBC Resources and create a new one with the right Connection Pool. If the Resource and the Connection Pool are missing, the deployment will fail!!! It worked for me without java:app/webservice...
Solution 2
I had this same issue and it manifested in a great holabaloo of various strange exceptions that had absolutely nothing to do with my actual issue.
What's happened?
For some reason the resource for jdbc/[your resource name]
has not been created in GlassFish and it throws you a jdbc/[your resource name]__[generated thing, like "pm"]
as the source.
What to do?
One way (the one I used) to fix this is to manually go into your GlassFish admin console in the browser at localhost:4848
and in the menu to the left go to Resources
and follow the tree inside it: JDBC > JDBC resources
. In the JDBC Resources
tab you create a new resource and name it jdbc/[your resource name]
the __[generated thing, like "pm"]
is not necessary.
BUT THAT DIDN'T WORK SO NOW WHAT DO I DO?!
This is exactly what happened to me and this is where I started getting the weird exceptions, like how it suddenly couldn't find my DB driver, even though I was staring at it in my dependencies folder.
How do I fix that then?
Restart NetBeans, refresh GlassFish and restart it if you have to. Run project and it should deploy.
(I found the source of my problem from an exception about a MDB and when I removed it, it suddenly worked with my added resource, and then I could re-name it to whatever I wanted as long as there was a matching resource in GlassFish. You may need to have a lookover of your MDB JNDI settings in GlassFish as well and manually create a resource for them)
Extra tip:
NetBeans will autocomplete existing resources when you're writing the <jta-data-source>
tag. If it doesn't autocomplete, it probably doesn't exist.
elpronto
Updated on October 27, 2020Comments
-
elpronto over 3 years
I am using the following:
- NetBeans IDE 7.3 (Build 201306052037)
- Java: 1.7.0_17; Java HotSpot(TM) 64-Bit Server VM 23.7-b01
- NetBeans integrated GlassFish Server Open Source Edition 3.1.2.2 (build 5)
I created an RESTful Webservice with NetBeans, deployed it under NetBeans and it worked fine.
So I copied the generated .war file to another machine which uses:
- Oracle GlassFish Server 3.1.2.2
- java version "1.7.0_21" Java HotSpot(TM) Client VM (build 23.21-b01, mixed mode)
When I want to deploy the .war file, I receive this error:
remote failure: Error occurred during deployment: Exception while preparing the app : Invalid resource : webservice__pm. Please see server.log for more details. Command deploy failed.
Here my 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>
Here is my 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>
Here is the error message from the 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)
I read a lot, that I should use java:app/webservice but it didn't work for me!!! Any other suggestions?
-
Fast Engy almost 9 yearsFurther for those having issues like this in Netbeans. By create a new one @elpronto means use make the JNDI name the same as your Data Source name in persistence.xml file.