Tomcat integrated in Eclipse DB connection - java

I'm finding a rather unusual problem. I have a web app that connects to my DB using the jdbc driver and creates the DB tables when the application is launched (hibernate hbm2ddl.auto=create). When I create a war and deploy it to tomcat from outside eclipse (simply copying the war to the webapps folder in tomcat) and launch the application, it creates the tables correctly. However, I integrated Tomcat with Eclipse(catalina_home set to the same tomcat installation as before, thus same config files).But this time, when I deploy the app from within eclipse, the tables are not created. I have tried a couple of things but nothing seems to work.
If you need more specific information please dont hessitate to ask.
Thanks in advance.

I had the opposite problem, where things worked in Eclipse but not Tomcat by itself. You may need to be very explicit about the connection method to the database, that is what helped me. See my question and answer at Tomcat JDBC connection works in Eclipse but not stand-alone.

Related

how to publish my jsp project on internet using tomcat,mysql and jdbc driver

I have completed my semester project using jsp,tomcat server,mysql database and jdbc driver.I dont have any idea how to publish it on internet.It is working fine in localhost.Please help.
Basically you need to purchase a domain and a hosting place. Your hoster should support Tomcat and MySQL service. Then you need to build up your database, and deploy your application on the Tomcat server. And voila!
Note: The jdbc driver is not an issue since it can be included within your application...

War file on Win Server Tomcat 8.0

I export my maven java project in Eclipse to War file.
On the server, I open the manager of tomact and add the war application, but when I run the application it seems the application isn't running (or some problem with the resources).
From the other hand, when I start the tomcat by the startup.bat in the tomcat folder and add the War to the webapps folder, it is working. But if I logoff the server , I cannot connect the application remotly. The server is shut down. Why?
What can be the problems?
Thanks!
Me
Why is your application not running? Well - if there's a specific reason for it (and the manager application works) you will see it in the logfile - e.g. tomcat's log/catalina.out. Check it or give us a snippet of the error messages in there if you don't understand them.
I like to recommend not to use the manager application, rather deploy through the OS or any other maintenance tool (e.g. scripted). This typically results in a better maintainable system. As it already works well for you when you just add your WAR file to the webapps directory, everything seems well. Introducing a manager application in production just provides another means to attack your site - and I frequently see those applications poorly maintained (and the passwords poorly chosen & protected)
When you start tomcat with startup.bat, it will run the server process in a console window. This console process will be shut down when you log out. In order to have tomcat running even when you're not logged in (and in order for it to start automatically), you'll have to install it as a service. There's plenty of information on the internet on how to do this - should be extremely easy to find.

Is it possible to run two servers on a same system simultaneously? Or how can I execute a MySQL query in Eclipse while XAMPP/WAMP is not running?

I have two questions, for those which I did not get any solution sounds good for my expectations.
1. Why both XAMPP/WAMP and Apache Tomcat?
Assume if I am now running a Windows system, with Eclipse LUNA.
Now, if I have to run a query for my localhost server, how does Eclipse help?
I won't be satisfied if you say there should be an XAMPP server running live for your query to execute in Eclipse(Like they say here Database Development Using the Eclipse IDE, MySQL with Eclipse Data Tools Platform in Java).
Then why Tomcat is there?
Sorry if there is some loop hole, or may be this is a Banana-Monkey` type question. All because I don't get it clear.
And now, my second question.
2. How can I(Is it possible to) run a Java project in Eclipse with Apache Tomcat while WAMP/XAMPP is running in background in my system?
Suppose I am on the same system working with different user privileges. Say user1 runs both the XAMPP and Eclipse As Administrator. Now (or anyhow) is it possible to run a project in Apache Tomcat while WAMP/XAMPP is running in background simultaneously in the system?
I am totally confused. Helps with your comments and answers are appreciated.
Thank you.
Yes it is possible to run two servers on same system simultaneously.
Yes you can execute a MySQL query when XAMP/WAMP is not running.
It seems you don't understand your setup and the elements involved.
XAMP/WAMP contains Apache server, so a http server that can handle static html or run php scripts. It also comes with a MySQL database.
So the only important part from the Java WebAPP is the MySQL. You can start MySQL without starting apache, you can finally install MySQL yourself (it has simple windows installer). But if your application is using MySQL it has to be running for it to work (be it a XAMP version or standalone version).
Your Java Web Application requires application container to run, and it is the Tomcat. It is Apache Tomcat as it is developed under apache groupe, but it is not the same as Apache web server.
So you need tomcat to run your web app. Again you can install one yourself or use the one that comes toghether with Eclipse.
You can have many tomcats at the same time, all running (for example different version of Tomcats or Java) as long as they listen on different ports. The ports on which tomcat is runing is configured in its server.xml file under conf directory.

Web application cannot establish connection to database

My application, when running on Tomcat, is not able to connect to my database when deployed as a .war in the webapps folder, but it can connect when I am running it through Eclipse directly. The code is exactly the same in both cases. In addition, other apps in the webapps folder, which originally could connect to the database, can no longer do so. The jdbc code is correct as I have tested it with offline applications or when running it through eclipse, but not when I access it on, say, Chrome, using localhost. What has happened to my tomcat server?
Note: the JDBC driver is the MS Access one.
The code is exactly the same in both cases.
No it's not; if it were exactly the same you'd be connecting properly.
but it can connect when I am running it through Eclipse directly
Does this mean that you have a main method that drives the code that connects properly? The way you do it is usually different from a web app - you know that, right?
If you could post an exception or log message it would help a great deal.
I'm guessing it could be any one of the following; guessing is necessary because you haven't provided enough information for a solid answer:
The JDBC driver JAR is not available when you run under one configuration; you'll see a ClassNotFoundException in that case.
You haven't configured a JNDI data source properly in Tomcat.
You didn't put the JDBC driver JAR in the Tomcat /lib directory.
Could be other possibilities.
UPDATE:
Since you're using Access, and providing no other information, I'm guessing that you're using a relative file path to get to the Access .mdb file. Your command line app that runs successfully in Eclipse works because you give a relative file path that is correct relative to the project root. When you deploy to Tomcat, that relative path is no longer correct, so your application can't find the database anymore.
Sounds like you aren't printing the stack trace for errors, so you're losing out on information that might help you figure this out.
Microsoft Access is not a multi-user database. A web based application running on Tomcat is certainly multi-threaded. You should not be using Access for a web application. I'd consider switching to another database.
First, you need to verify the path to your database file. In fact, I believe it has to be an absolute path for tomcat to work correctly. The simplest thing to do is to put your database file in C:\data or similar and then hard code the path in your code. Of course, the file will be outside of your war and thus not portable (i.e., deployable to a remote server).
Second, you do need to make sure that the JDBC driver is available. If you use Class.forName in your code to load the driver, you will only need to make sure that the jar containing the driver is in the tomcat classpath (which would include the lib directory of your webapp). If you use the -Djdbc.drivers JVM flag approach, you will need to add it to the tomcat startup scripts.

Deploy Java EE Project in Weblogic

I have WebLogic installed in my computer. I already added it as a server in my Eclipse IDE. How do I configure my Web application to run or for it to be deployed on the WebLogic server. I found a sample project and found a weblogic.xml in it. Where do I start? Do I need to add something, etc.
If your web application is already a "Dynamic Web Application", then you should be able to deploy it just by right clicking on it, then Run As > Run on Server and choose the WebLogic Server runtime.
If this doesn't work, maybe you need to add the right facet to your project. Right click on your project and go to Properties > Project Facets and check that Dynamic Web Module is checked.
If this still doesn't work, maybe recreate a "Dynamic Web Application" from scratch and move (or copy) your sources to this newly created project.
Many tutorials are actually available at the WTP Community Resources page. See for example Using the Eclipse Web Tools Platform with Apache Tomcat. It is not specific to WebLogic but if you already have it setup in Eclipse, it should be easy to adapt the specific parts.
PS: It's hard to say anything about your sample project and the weblogic.xml as you didn't provide any detail about them. Maybe try to follow the advices above and, if you still have problems, update your question with more information.
There are a number of resources on using Eclipse with WebLogic, including Oracl'es Enterprise Pack for Eclipse. It's hard to tell without more information, but you need a WebLogic Domain configured with at least an Admin Server to deploy the web application to. When doing local development, it's acceptable to deploy applications to the Admin Server, but beyond this you typically want an Admin Server and a managed server where the application will get deployed to.
Here's some info on Eclipse and WebLogic - http://www.oracle.com/technetwork/developer-tools/eclipse/learnmore/index.html
Question is missing much details. You can find some detailed help here
http://download-llnw.oracle.com/docs/cd/E13222_01/wls/docs90/deployment/index.html

Categories