3

I have created a Java EE Technologies dynamic web project in Eclipse. The project creates a database within it. Testing it on a local machine having Tomcat server works fine. I want to deploy this project with the database to another system running Tomcat.Because I need to deliver my project to Customer place. How to accomplish this task?

And Is there any possibilities to build war file with sql table.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
  • 1
    What does _The project creates a database within it_ means? Does it create it from Java code? Did you tried to deploy it on a dummy external server (e.g. on a virtual machine)? – Narmer Oct 16 '14 at 09:08
  • @Narmer project is like ERP. If we create it from java code means every time the code runs table will create knw it may create some problem but im not sure –  Oct 16 '14 at 09:13
  • @Narmer and also many details are predefined in some tables how to import that?? –  Oct 16 '14 at 09:15
  • You have to export your tables and threat the web app and the database separately. Why are them bonded togheter? (Couldn't find anything related to ERP outside of [Enterprise Resource Planning](http://it.wikipedia.org/wiki/Enterprise_resource_planning), is this what you meant?) – Narmer Oct 16 '14 at 09:19
  • @Narmer not exactly ERP narmer, So in that i need to export some of the tables in build that is why am struggling –  Oct 16 '14 at 09:23
  • @Narmer i need to create war file with database tables. Is that Possible??? Pls if possible let me know –  Oct 16 '14 at 09:28
  • No it is not possible to create *a war file with database tables*. How did you create the tables for your test ptoject? What technologies do you use for accessing the database? As it is your question is too brad and unclear. – A4L Oct 16 '14 at 12:45
  • @A4L am using tomcat server and mysql as database and JEE Technologies –  Oct 16 '14 at 13:02
  • @A4L if possible pls let me know and send me some links –  Oct 16 '14 at 13:07
  • JPA? Hibernate? persistance.xml? hibernate.cfg.xml? You can configure those to automatically create database for you. But it is not adviceable and you still need to provide DB-user/password and URL from outside. How did you create DB for your test project? – A4L Oct 16 '14 at 13:09
  • @A4L am using mysql workbench in my system so i dont want to install mysql workbench in every third party system –  Oct 17 '14 at 04:25
  • yet another false claim of people who dont even know what they're talking about ... its kinda hilarious – specializt Oct 18 '14 at 11:23

1 Answers1

2

In most of the cases the answer is NO, you can't export a .war with an embedded database created with eclipse.

You have to export your database files separately and upload them on the production server. This usually means that you have to install the database server you used while developing and export your DDL and table data.

In your particular case (MySQL with Tomcat) we can say that MySQL is not built for embedded use, unless using an out of date and not quite complete MySQL Embedded Library for Java, which would led you to some major changes in your project DB configuration.

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

This is taken directly from an Eclipse Corner Article on Creating Database Web Applications with Eclipse.

BEWARE!!: the linked article is deprecated thus you should not rely on it completely. The quoted part is still sensitive for your case and covers a Derby database deploy.

Deploying the Database

When you are ready to deploy the application to a production Tomcat application server, you must copy the Derby database data folders to the application server computer. You then have a couple of options for accessing the Derby database from your deployed application.

You can install Derby on the application server computer, and run it in client/server mode. Your application connects to the database using the same technique as I've demonstrated in this article. The drawback to this approach is that you have two server processes to manage: Tomcat and Derby.

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

Community
  • 1
  • 1
Narmer
  • 1,414
  • 7
  • 16
  • this answer is wrong and misleading, it is of course possible to store a whole DB inside a war - this file (XML, for example) will have to be inserted into a running DB at WAR-startup and synchronized at shutdown, of course - but it definitely is possible. – specializt Oct 16 '14 at 10:03
  • @specializt I think the OP meant to upload the whole DB, server included, in a Tomcat environment. Like you said, the DB must be running at startup, thus the DB must be deployed first. If what the OP wants is only to load DDL and data from the war it is possible like you said (I even think some frameworks make it really easy to do). – Narmer Oct 16 '14 at 10:29
  • The only way to do that AFAIK is to use [Derby embedded](http://stackoverflow.com/q/3449827/3735079), as mentioned in my answer. – Narmer Oct 16 '14 at 10:33
  • @specializt hi sir can you please explain me how to import table inside war and if possible send me some links –  Oct 16 '14 at 10:35
  • [link](http://stackoverflow.com/questions/3449827/apache-derby-embedded-mode-deployment) [link](http://stackoverflow.com/questions/4443192/how-to-embed-h2-database-into-jar-file-delivered-to-the-client) – specializt Oct 16 '14 at 11:46
  • @specializt but am using apache tomcat server and mysql database –  Oct 16 '14 at 12:01
  • @specializt sry i couldn't get u –  Oct 16 '14 at 12:10
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/63164/discussion-between-anand-and-specializt). –  Oct 16 '14 at 12:13
  • @specializt You linked some very particular configurations, while OP was talking about a standard (Tomcat-MySQL), that's exactly my point: what he wants to do is impossible without major changes in his project. BTW I rollbacked my answer to first revision, where I mention that in most cases is impossible (just to avoid misconceptions like yours). – Narmer Oct 16 '14 at 12:18
  • 1) i copied your own link (!) 2) there is literally no case in which this is impossible, including his - and integrating a embedded database surely cant be called "major change". With maven, one simply would have to include a few dependencies and write a small configuration-class, maybe coupled with a few more DBMS-specific files, thats it. The only interesting part will be the placement of the database-files and the according DBMS-configuration – specializt Oct 16 '14 at 12:27
  • Ok, if it's possible and simple to embed a MySQL server in a war just answer the question providing your solution (I'm serious, now I'm also curious), there's no need for us to discuss here :) – Narmer Oct 16 '14 at 12:31
  • hokay, i shall get on it sometime ... maybe this evening, maybe on saturday ... we'll see. – specializt Oct 16 '14 at 13:15
  • @specializt yeah sure am also waiting for ur solution –  Oct 17 '14 at 04:21
  • apparently i cant post a answer anymore - it doesnt make any sense whatsoever that this question got locked since there is only one possible solution, but OK : http://dev.mysql.com/doc/refman/5.6/en/libmysqld.html Apprently you can embed a full mysql-server into your application and judging from the doc its also fairly easy to use. You will have to call these functions via JNI aaand you're ready to go. – specializt Oct 18 '14 at 11:22
  • @specializt _The embedded server library is based on the client/server version of MySQL, which is written in C/C++. Consequently, the embedded server also is written in C/C++. There is no embedded server available in other languages._ How does this help the OP? How can he add his C++ server into Tomcat? You went from a _there is literally no case in which this is impossible_ to a _there is only one possible solution_ which is also not feasible for the OP. – Narmer Oct 20 '14 at 09:49
  • using C/C++ - libraries within java is somewhat easy : JNI. As there are only a few usable functions the JNI class / method-declaration will be really easy. And now please stop assuming things and mangling statements to your will "there is only one possible solution ..." has nothing to do with "there is not one single case in which it is impossible to embed a mysql-sever into your application". Some languages need to use frameworks like JNI, some can call native c functions directly. – specializt Oct 20 '14 at 10:20
  • Really you think that using JNI to embedd a MySQL C++ server in a war application to be uploaded in a Tomcat environment is _somewhat easy_ for the OP? I think you are clutching at straws by now. Clearly the OP is not going to use your solution and clearly what he wants to do is impossible. There are infinite ways to do everything, you can also write a MySQL server Java library yourself. Is this a good choice for the OP? Stop being so rude and try to be collaborative. – Narmer Oct 20 '14 at 10:29
  • I apologize if you found that I _mangled statements to my will_, but since you said that no case is impossible I espected a solution specifically suited for the OP. My bad to understand that not correctly. – Narmer Oct 20 '14 at 10:31
  • his attempt has never been impossible, no matter how much you want to spread this fantasy. I'll get back to my "straws" now, mmmmkay – specializt Oct 20 '14 at 14:43
  • Yep, that's why he resolved his issue. Thus I consider the matter closed. – Narmer Oct 20 '14 at 14:48