使用Java EE 7 GlassFish 4.0 Restful Web服务和Netbean并在Glassfish 4.0上进行部署 [英] Java EE 7 GlassFish 4.0 Restful Webservices using and Netbean and deploying on Glassfish 4.0

查看:148
本文介绍了使用Java EE 7 GlassFish 4.0 Restful Web服务和Netbean并在Glassfish 4.0上进行部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已按照本教程使用Netbean创建简单的Java EE 7 Web服务7.3.1.我有运行Netbeans的Glassfish 4.0.我成功运行了项目,没有任何问题.

下一步是在独立版本的GlassFish 4.0 Web服务器上部署Webservice项目.这样我就可以在没有Netbeans的情况下运行它.

http://localhost:4848上使用Glassfish Web界面并导航

Common Taks -> Applications -> Deploy

我使用(打包文件上传到服务器")浏览,然后从项目的子目录/dist/

中选择CustomerDB.war文件.

我通过在Netbean中运行项目创建了war文件.

但是部署失败,并出现以下错误.

Error occurred during deployment: Exception while preparing the app : Invalid resource Please see server.log for more details.

当我检查服务器日志C:\ glassfish4 \ glassfish \ domains \ domain1 \ logs \ server.log

[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   ]]

更新:

好的,我忘记添加连接了,因此找到了上述问题的解决方案. 我刚刚添加了连接池和连接资源.

通过导航Common Tasks -> Resources -> JDBC -> JDBC Connection Pools添加了JDBC连接池.

通过导航Common Tasks -> Resources -> JDBC -> JDBC Resources

添加了连接资源.

但是我仍然遇到错误.这次不一样了.

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.

有什么想法我想念吗?

解决方案

要解决第一个问题,请从您的项目中打开您的glassfish-resource.xml文件,它看起来像这样.

如果服务器配置文件夹中没有glassfish-resource.xml,则还可以通过单击netbeans中的服务"选项卡并进一步单击连接池来检查这些详细信息,如此屏幕快照所示.

基于其中的信息,并使用Glassfish 4.0 Web界面http://localhost:4848

首先通过导航创建新的JDBC连接池 常见任务->资源-> JDBC-> JDBC连接池. 它看起来像这样.

然后通过导航创建Connection资源 常见任务->资源-> JDBC-> JDBC资源 看起来像这样.

第一个问题已排序.您可以使用连接池中的Ping按钮对其进行测试

第二个问题. (如果您的ping操作不成功,请执行以下操作)

在Netbeans安装文件夹中搜索mysql-connector-java-5.1.23-bin.jar文件并将其复制到Glassfish库文件夹

C:\glassfish4\glassfish\lib

复制后停止&通过在文件夹C:\glassfish4\glassfish\bin

中运行以下命令来启动服务器

asadmin.bat stop-domain domain1
asadmin.bat start-domain domain1

在上面之后,再次部署该应用程序,它将成功部署,您可以使用测试界面访问它 http://localhost:8080/CustomerDB/test-resbeans.html与netbeans完全相同.

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?

解决方案

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.

这篇关于使用Java EE 7 GlassFish 4.0 Restful Web服务和Netbean并在Glassfish 4.0上进行部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆