将Java应用程序部署到Tomcat的问题 [英] Issues deploying a Java application to Tomcat

查看:210
本文介绍了将Java应用程序部署到Tomcat的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了一个简单的Java Web应用程序.它为用户提供了一系列RESTful API,以通过Web界面在Java DB上执行某些操作.在开发过程中,我使用了NetBeans环境,并在测试中使用了Glassfish.

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).

我安装了Tomcat 7,并将.war文件移动到Tomcat的webapp文件夹中.应用程序将部署.此后,我尝试使用为此创建的按钮从数据库读取一些数据,但出现以下错误

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

我不确定出了什么问题,但是我有两种理论.

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

1)Web应用程序无法连接到数据库.但是,当我尝试再次运行该应用程序时,从NetBeans启动JavaDB之后,没有任何区别.

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)不知何故,应用程序无法访问Node服务.我以为在移动应用程序时无需更改API链接,但是也许我错了.

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.

使用TomEE解决了该问题.

The issue was solved by using TomEE.

推荐答案

该错误来自您选择的应用程序服务器. TomCat只是一个Servlet容器(意味着它仅支持Servlet/JSP). 其他任何功能(JAX-RS,CDI等)都需要Java EE认证的服务器,例如GlassFish,WildFly,Payara,WebLogic,OpenLiberty或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 可能是最好的选择.基本上是TomCat + Java EE的其他功能.

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.

TomEE没有用于GlassFish之类的JNDI数据源配置的GUI,您需要编辑conf/tomee.xml

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

<Resource id="myDataSource" type="javax.sql.DataSource">
    jdbcDriver = org.apache.derby.jdbc.ClientDriver
    jdbcUrl = jdbc:derby://localhost:1527/dbname
    userName = app
    password = app
</Resource>

在您的Java代码中:

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.

这篇关于将Java应用程序部署到Tomcat的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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