问题
I have followed this Tutorial to Create simple Java EE 7 Webservices using Netbean 7.3.1. I have Glassfish 4.0 running with Netbeans. I ran project successfully without any problem.
Next Step is to Deploy Webservice project on standalone version of GlassFish 4.0 webserver. So I can run it without Netbeans.
Using Glassfish web interface on http://localhost:4848
, and navigating
Common Taks -> Applications -> Deploy
I browse using ("packaged file to be uploaded to the server") and Select the CustomerDB.war file from my project's sub directory /dist/
I have created the war file by running project in Netbean.
But Deployment Failed with following Error.
Error occurred during deployment: Exception while preparing the app : Invalid resource Please see server.log for more details.
When I checked Server Log C:\glassfish4\glassfish\domains\domain1\logs\server.log
It says
[2013-08-20T16:15:07.633+0100] [glassfish 4.0] [INFO] [] [org.glassfish.admingui] [tid: _ThreadID=33 _ThreadName=admin-listener(2)] [timeMillis: 1377011707633] [levelValue: 800] [[
Exception Occurred :Error occurred during deployment: Exception while preparing the app : Invalid resource ]]
UPDATE:
OK I find the solution of above problem as I forget to add the connection. I just added Connection pool and connection resrouces.
Added JDBC connection pool by navigating Common Tasks -> Resources -> JDBC -> JDBC Connection Pools
.
Added the connection Resources by navigating Common Tasks -> Resources -> JDBC -> JDBC Resources
But I am still getting error. This time it is different.
Error occurred during deployment: Exception while deploying the app [CustomerDB] : Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlDataSource Error Code: 0. Please see server.log for more details.
Any Idea what I am missing?
回答1:
To Fix First problem, open your glassfish-resource.xml
file from your project, it will look something like this.
if you don't have glassfish-resource.xml in server-configuration folder you can also check the these details by clicking on services tab in netbeans and furhter clicking on connection pools as shown in this screenshot.
Based on the information in it, and using Glassfish 4.0 web interface http://localhost:4848
Firstly Create new JDBC connection pool by navigating Common Tasks -> Resources -> JDBC -> JDBC Connection Pools. It will look something like this.
Then Secondly create Connection resource by navigating Common Tasks -> Resources -> JDBC -> JDBC Resources It will look somehting like this.
First Problem is sorted. you can test it using Ping button in connection pools
For Second problem. (if your ping is not successful do following)
Search mysql-connector-java-5.1.23-bin.jar
file in Netbeans installation folder and copy it to Glassfish library folder
C:\glassfish4\glassfish\lib
After copying stop & start server by running following commands in folder C:\glassfish4\glassfish\bin
asadmin.bat stop-domain domain1
asadmin.bat start-domain domain1
After above, deploy the application again and it will successfully deployed and you can access it using test interface
http://localhost:8080/CustomerDB/test-resbeans.html
exactly the way as in netbeans.
来源:https://stackoverflow.com/questions/18339081/java-ee-7-glassfish-4-0-restful-webservices-using-and-netbean-and-deploying-on-g