简体   繁体   English

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

[英]Issues deploying a Java application to Tomcat

I built a simple Java web application. 我构建了一个简单的Java Web应用程序。 It provides a series of RESTful APIs for the user to carry out certain operations on a Java DB through a web interface. 它为用户提供了一系列RESTful API,以通过Web界面在Java DB上执行某些操作。 I used NetBeans environment during the development, and Glassfish for testing. 在开发过程中,我使用了NetBeans环境,在测试中使用了Glassfish。

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. 我安装了Tomcat 7,并将.war文件移动到Tomcat的webapp文件夹中。 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) The web application cannot connect to the database. 1)Web应用程序无法连接到数据库。 Yet when I attempted to run the application again, after starting JavaDB from NetBeans, there was no difference. 但是,当我尝试从NetBeans启动JavaDB之后再次运行该应用程序时,没有任何区别。

2) Somehow, the application cannot reach the Node service. 2)以某种方式,应用程序无法访问Node服务。 I assumed that there will be no need to change the API links while moving the app, but perhaps I was wrong. 我以为在移动应用程序时无需更改API链接,但是也许我错了。

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. 编辑:通过使用TomEE解决了该问题。

The error is come from your application server of choice. 错误来自您选择的应用程序服务器。 TomCat is only a servlet container (means it only support Servlet/JSP). TomCat只是一个Servlet容器(意味着它仅支持Servlet / JSP)。 Any other feature (JAX-RS, CDI etc) require a Java EE certified server eg GlassFish, WildFly,Payara, WebLogic, OpenLiberty or TomEE. 任何其他功能(JAX-RS,CDI等)都需要Java EE认证的服务器,例如GlassFish,WildFly,Payara,WebLogic,OpenLiberty或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. 如果要在生产或测试环境中使用TomCat, TomEE可能是最好的选择,它基本上是TomCat + Java EE的其他功能。

EDIT: TomEE don't have a GUI for JNDI datasource configuration like GlassFish, you need to edit conf/tomee.xml 编辑:TomEE没有像GlassFish这样的JNDI数据源配置的GUI,您需要编辑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>

And in your java code: 在您的Java代码中:

@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. 您可以在此处查看有关数据源的更多详细配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM