java应用程序部署,将Java应用程序部署到Tomcat的问题

I built a simple Java web application. It provides a series of RESTful APIs for the user to carry out certain operations on a Java DB through a web interface. I used NetBeans environment during the development, and Glassfish for testing.

Now that I finished it, I would like to be able to deploy it on another machine using binaries (although as for now I use the same machine until I learn how to do it).

I installed Tomcat 7, and moved the .war file into Tomcat's webapp folder. The application deploys. Thereafter I try to read some data from the databse using a button I created just for this, but get the following error

vzJL0.png

I am not sure what went wrong, but I have two theories.

1) The web application cannot connect to the database. Yet when I attempted to run the application again, after starting JavaDB from NetBeans, there was no difference.

2) Somehow, the application cannot reach the Node service. I assumed that there will be no need to change the API links while moving the app, but perhaps I was wrong.

Or maybe there is some other issue I did not consider? I will be grateful for any advice about how to properly deploy such an application.

EDIT: The issue was solved by using TomEE.

解决方案

The error is come from your application server of choice.

TomCat is only a servlet container (means it only support Servlet/JSP).

Any other feature (JAX-RS, CDI etc) require a Java EE certified server e.g. GlassFish, WildFly,Payara, WebLogic, OpenLiberty or TomEE.

TomEE could be your best bet if you want to use TomCat in your production or test environment, it is basically TomCat + Java EE other feature.

EDIT:

TomEE don't have a GUI for JNDI datasource configuration like GlassFish, you need to edit conf/tomee.xml

jdbcDriver = org.apache.derby.jdbc.ClientDriver

jdbcUrl = jdbc:derby://localhost:1527/dbname

userName = app

password = app

And in your java code:

@Path("resources")

@Stateless

public class MyResources{

@Resource(name="myDataSource")

DataSource dataSource;

@GET

public Response SomeMethod(){

//Do stuff here

}

}

You can check here for more detail configuration on data source.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值