How to export war file with sql database table in eclipse

I created a dynamic web project Java EE Technologies in Eclipse. The project creates a database in it. Testing it on a local machine with Tomcat server works fine. I want to deploy this database project on another system using Tomcat. Because I need to deliver my project to the client's site. How do you accomplish this task?

And is there any possibility to create a war file with sql table.

+3


source to share


1 answer


In most cases the answer is NO , you cannot export a .war with an embedded database built with eclipse.

You need to export the database files separately and upload them to the production server. This usually means that you need to install the database server that you used to develop and export your DDL data and tables.

In your specific case (MySQL with Tomcat), it can be said that MySQL is not built for embedded use unless you use the outdated and incomplete MySQL Embedded Library for Java , which would lead you to some significant configuration changes to your project.

You can change your DB server by switching from MySQL to Derby or H2 (thanks to @specializt for this), which have the ability to embed the server directly into your war.



This comes directly from the Eclipse Corner article on Building Database Web Applications with Eclipse .

CAUTION!! : the linked article is out of date so you shouldn't rely on it entirely. The part quoted is still sensitive to your case and covers deploying a Derby database.

Deploying a Database

When you are ready to deploy your application to the production Tomcat application server, you must copy the Derby database data folders to the application server machine. Then, you have several options for accessing the Derby database from your deployed application.

You can install Derby on an application server machine and run it in client / server mode. The application connects to the database using the same technique as in this article. The downside to this approach is that you have two server processes: Tomkat and Derby.

You can use Derby in embedded mode. In this case, the Derby engine runs inside the Tomcat process. You don't have to stop and start Derby separately from Tomcat. For more information see the Derby site.

+2


source







All Articles