I am developing a web application and have hit a wall and could use some advice. So the application was written by a coworker who is no longer at our company. They wrote a web application for Apache Tomcat with Java and Javascript in the back end. The application makes use of the JDBC api to interface with a SQL Server database. This person did all the development in Eclipse and running it this way.
I am trying to take this web application and move it to a server. I attempted this by using Eclipse to export a WAR file and then placing this within the Tomcat webapps folder. Then when I started Tomcat the program was extracted. So far so good. The website comes up and works well. However, when I try to access the pages which rely upon database info everything is coming up NULL. I went through the Tomcat logs and found that in the standard out the following message was given:
ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
I had assumed that the WAR file would include all dependencies but I am guessing that probably this is not the case. If anyone is experienced, is this what has happened? If anyone out there is aware, is there a way to tell Eclipse to do this? Otherwise, what is my option? I am not a Java dev and so I would not know how to install JDBC if needed.
Any help is appreciated.
Mike
You can do the following
Go to Microsoft JDBC Driver download page and download the JDBC driver and install it to a location.
Open the .war file using a zip utility like 7-zip or winzip.
Copy the sqljdbc.jar from the sqljdb_4.0/enu directory where you installed the downloaded JDBC driver and paste it in WEB-INF/lib of the extracted war file.
Zip it back as .war file and deploy it again.
This will get the application running.
If you want to fix this permanently, then you should add the stop to include sqljdbc.jar to your WEB-INF/lib while building war file, in your build system, i.e. in build.xml if you are using ANT or in your Maven's pom.xml under dependencies section for this particular dependency.
You don't need to do the "Export WAR > copy to tomcat > start tomcat" manually, you could configure eclipse to do the deploy directly in your tomcat installation, firts double click tomcat server, and then select "Use tomcat installation" in the "Server Locations" section.
Make sure that your application contains the SQLServer JDBC driver (sqljdbc4.jar) in your project WebContent/WEB-INF/lib directory (assuming your coworker used the Eclipse "Dynamic Web Project" for the project layout), if not, download from here, unzip and copy it to the mentioned folder, the next time you start tomcat, it will automatically add it for you.
If the project uses the maven project layout (there is a file named pom.xml in the project root folder), use the following instructions to install the dependency in your local repository (there are some disagreements between Maven and Microsoft about licensing and redistribution of the driver, so there is no repo)
Related
I downloaded Eclipse Luna and Tomcat 8.0.24 some months ago but I started using it. I've been creating a web app without Maven. I downloaded manually Jersey 2.23, Jersey media moxy 2.23, java-son 1.0 , jdbc mysql 5.x and sql2o 1.5.4. I'm starting to learn Angular and I successfully created one page without any issue.
I remember have added my jars manually in the Build Path of my project and I was forced to add them in the Deployment Assemblies also. Fine.
Since 2 weeks I didn't shutdown my laptop, just in sleep mode. But yesterday I did shutdown. Since then I suffered to make it work again. I use postman chrome to test my restful services and I received after the shutting down the 404 error.
I realized that I started to see the exception in the console:
java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer
I deleted my folders of tomcat and eclipse to start again from scratch desperately. However, I got the same issue. The last thing that I remember I was playing with, were these modified options.
Double click in server from servers tab
Change from Use workspace metadata to Use Tomcat installation
Properties in Server
Switch Location from metadata to localhost.server
It was thanks to these questions that I solved my issue:
org.glassfish.jersey.servlet.ServletContainer ClassNotFoundException
java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer
Now, after "reinstalling" eclipse and tomcat, when I add the jars in the library tab, they are now added in deployment assemblies automatically. (Surprised)
According to the previous attached questions, I added all the jars in WEB-INF/lib from my workspace as also in the tomcat/wtpwebapps/myproject/WEB-INF/lib. If I don't do this, I won't be able to make it work. Postman finally gives me the desired output.
Nevertheless, I realized when I copy the jars manually through windows explorer, the console in Eclipse displays the tomcat restarting again. BUT I still see the exception: java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer. At least I can run my project in the browser or in postman without any issue. Very strange.
I want to add a new User Library in Windows > Preferences > Java > Build Path > User Libraries, but my list is EMPTY!!! So...
Finally, my questions:
What's going on with Eclipse?
Why am I not able to see my user libraries previously added?
Why do I still see the exception of glassfish.jersey in the console if I added the jars in the web-inf folder which makes it work apparently.
Why do I need to add the jars in web-inf, if when I see all the jars included in the Tomcat library all my jars are there because I forgot to mention that I added a folder called External in lib of my Tomcat folder.
For all these changes, I restarted Eclipse
Instead of adding jars manually, use maven and let the maven manage dependency of jars.
ClassNotFoundException occurs when you don't have a jar in the classpath. Maybe the package you are deploying on the server is not bundled correctly. Make sure you have jar bundled in your package or present in the classpath.
Another reason could be you have duplicate class files in two jars and the class your programme picking is not suitable.
I'm working on Java project for a portal. I checked out a sample portal from an svn, and pasted a renamed copy of it in the eclipse package explorer.
When I tried to run this new project on a Tomcat 7 server, I got the error message:
Could not publish server configuration for Tomcat v7.0 Server at localhost.
Multiple Contexts have a path of "/SamplePortal".
What do I need to do to get this new project to run?
All the suggestions in this thread are valid. If you extract the war file into a folder inside of Tomcat's webapps folder, it should work.
If you are trying to do it from Eclipse, make sure the file server.xml is not corrupted, or that Eclipse is not misreading it. Restart Eclipse if that is the case.
You need to change the name of your project directory or .war file so it doesn't conflict with the existing SamplePortal project.
I created a client using proxy in Oracle JDeveloper to call web service. JDeveloper deployed automatically and the code works well under windows environment. But now I'm required to migrate the code to unix server. I deployed the project to a .war file and copy it to unix which cannot be executed correctly using "jar" command.
Could anybody give me a whole picture or a high-level step-by-step instruction about what I need to set up to execute war on unix? I'm new to this area, and for now I got some suggestions like installing a Tomcat first.
What I have now:
1. a war file including .class, .java, WEB-INF, META-INF, MANIFEST.MF deployed from JDeveloper
2. JDK 1.6.0_25 installed on unix usr/java/
3. Tomcat installed on unix, but not under bin or local or usr directory(is it ok?)
Some specific questions:
1. what else do I need?
2. where to drop the .war?
3. do I need to unzip or re-compile the war?
4. how can I run the main class in the war?
Errors poped-up now:
1. cannot find main class
2. I tried to un-zip war and compile the class including main, and get "cannot find symbol" for the webservice specified classes' name.
Thanks to whoever attempt to help!
Even though this question probably should've been asked on ServerFault instead of here, sounds like you got all you need. Try dropping the .war on tomcat's webapps directory.
You should be able to just drop the .war file in $CATALINA_BASE/webapps and tomcat should pick it up when you start it.
$CATALINA_BASE is where you installed tomcat, unless you've configured tomcat for multiple bases.
You only need a war file if you are developing web application. From what you describe, you need to create a zip file which contains all the libraries and classes you need and copy it to Unix. Then you unpack it and execute it using java command.
Alternatively you can create a jar file with all dependencies included using Maven Shade Plugin and execute your code using jar command.
I have a java based web application, which has certain java files and due to some need, i have added some jar files with in the project and made it project specific.
Now, While deploying them in production, I see, that the web file server (tomcat6) already has those jar files in its global library. Now, How do i remove reference of that jar file it, with out disturbing my code(which is working fine).
I saw in other article saying we just have to change the build path to refer the global library instead of local library.
Finally I have 2 questions.
How to do this?
If i'm working on windows and using path while configuring the build path, will it not be a problem if i deploy it in Unix environment.?
Please suggest. Also, its the problem with servlet-api.jar.
I use eclipse IDE. So how to perform these changes in eclipse?
Open your web project in eclipse and right click on the project. click on Properties and then choose build path and remove the jars you want to remove under the tab 'Libraries' and then export the war and deploy it in your tomcat6 server. if you want to run your web application in eclipse, you have to configure the server libraries by clicking 'Add Library' button in build path and then choose server runtime and choose the tomcat6 server configured in eclipse. Hope this helps
I have downloaded a sample extjs+mysql+spring web project (link) with a java backend that I'd like to set up locally on my machine. I have installed Tomcat server, and MySQL DB but it's my first time ever with a java-based web application and I have troubles setting it up. Does it require any modifications ? I thought that .jsp files should be included there, but I can only see .java sources. Do I need to build it before it's ready for deployment ? Any help appreciated.
This is an Eclipse project so you'd need to run it from within Eclipse.
Download Eclipse
Open the project in it
Define a Tomcat container in your Servers tab
Drag and drop the project onto the newly defined Tomcat
Run it
if your are using eclipse IDE for development, create a project in eclipse,
run as "run on server" , and set the running server (eg TOMCAT 7).
and thats it,,
make sure, you correctly setup spring project in IDE with all needed jar files .