My servlet application uses JavaMail API and Java Activation Framework (JAF). I do development in IntelliJ IDE. TomCat runs on the same local Windows machine. When I try to run my Servlet from IntelliJ I have error related to fact TomCat not finds mentioned libraries. What is the right place to store libraries for TomCat? Is it possible ask IntelliJ to place required libraries to TomCat ?
Put the jar files in the WEB-INF/lib folder. If there isn't one, create one manually.
This way the jar files are added to the war file that gets created when you build your artifact, and tomcat knows where to find those jars at runtime.
Related
I'm using Eclipse 3.7 (STS) with Tomcat 7 running inside the IDE. I've created a new Dynamic Web project and added a single JSP file to the web content root folder. I can run Tomcat and access the JSP from within Eclipse with no problems.
I've added a few 3rd party JAR's to the project from User Libraries (I'm not using maven or auto dependecies managment). In the JSP I reference a class from the project's JAR file, I can compile this with no problem, but when I deploy on Tomcat the JSP throws ClassNotFoundException. Clearly, Tomcat can't find the JAR's from my library settings. I tried creating a Run As configuration for Tomcat Server and I set the classpath to match the classpath settings of the project, but I still get the same classnotfound problem.
I could get around the issue by manually copying all project JARs to the WEB-INF/lib directory so the webapp can find all dependencies, but that's absurd and I don't expect that to be the solution since it's a maintenance nightmare.
Am I missing something?
In project's properties, go to Deployment Assembly. Add there the buildpath entries as well which you've manually added as user libraries. It'll end up in /WEB-INF/lib of the deployed WAR.
You'll need to copy the jar files to the WEB-INF/lib folder: that is where they are supposed to be.
Eclipse should offer you the option of generating a WAR file that includes all the dependencies: I haven't used Web Tools for a good while but one way or another all dependencies have to be in WEB-INF/lib or the class loader won't be able to find them.
I'm trying to learn Java and want to write a basic webapp using Vaadin (and Maven) in Eclipse.
I have a single java file which should create a window with a single panel.
I have a tomcat server setup, but when I try and run my project on that I can't get past this error:
java.lang.ClassNotFoundException: com.vaadin.server.VaadinServlet
I have "vaadin-server-7.6.4.jar" installed in my Maven dependencies folder, so I am guessing I haven't set the paths correctly in the web.xml (or pom.xml?).
Any ideas where I should start troubleshooting this?
Check if the jar is present in the Classpath. Either that jar should be inside the lib folder of Tomcat installation directory or it should be packaged in the lib folder of the web app.
I'm using Eclipse 3.7 (STS) with Tomcat 7 running inside the IDE. I've created a new Dynamic Web project and added a single JSP file to the web content root folder. I can run Tomcat and access the JSP from within Eclipse with no problems.
I've added a few 3rd party JAR's to the project from User Libraries (I'm not using maven or auto dependecies managment). In the JSP I reference a class from the project's JAR file, I can compile this with no problem, but when I deploy on Tomcat the JSP throws ClassNotFoundException. Clearly, Tomcat can't find the JAR's from my library settings. I tried creating a Run As configuration for Tomcat Server and I set the classpath to match the classpath settings of the project, but I still get the same classnotfound problem.
I could get around the issue by manually copying all project JARs to the WEB-INF/lib directory so the webapp can find all dependencies, but that's absurd and I don't expect that to be the solution since it's a maintenance nightmare.
Am I missing something?
In project's properties, go to Deployment Assembly. Add there the buildpath entries as well which you've manually added as user libraries. It'll end up in /WEB-INF/lib of the deployed WAR.
You'll need to copy the jar files to the WEB-INF/lib folder: that is where they are supposed to be.
Eclipse should offer you the option of generating a WAR file that includes all the dependencies: I haven't used Web Tools for a good while but one way or another all dependencies have to be in WEB-INF/lib or the class loader won't be able to find them.
I was going through java tutorials and found that after creating the servlet they have added the servlet.jar file using build path opt. But in my case servlet is still working without that external jar file.
So what is the need of that external jar file?
It's still working fine in your case because
Just check below
Right click on your project then go to Properties -> Targeted Runtime -> Apache tomcat
If you have selected that checkbox you no need to add servlet jar and if it's not then you need to add servlet jar in lib folder
So in your case you must have selected targeted runtime that's why even though u have not added servlet jar file it's working fine
You don't need to add because you may have added Apache Tomcat as server run time in for your web project and Apache tomcat has servlet.jar in its lib folder so it will be there
you can check it by going in Apache tomcat folder > lib
You need Servlet-api.jar to compile servlets in eclipse but while deploying servlet container ( like tomcat ) will have it built in. Infact it is bad practise to include it inside your WEB-INF/LIB folder.If you configure your eclipse to use libraries from tomcat(or other servlet containers) then you might not need it manually.
Servlet-api.jar is by default provided by the container environment. So you should not put it in your WEB-INF/LIB folder when you are deploying your application. However, it is required for compiling your Servlets. In case if you are using Eclipse as your IDE, place it in your classpath using Add External JAR files option.
Ensure that you're using at least Eclipse IDE for Java EE developers (with the EE). It contains development tools to create dynamic web projects and easily integrate servletcontainers (those tools are part of Web Tools Platform, WTP). You also need to ensure that you already have a servletcontainer installed which implements at least the same Servlet API version as the servletcontainer in the production environment, for example Apache Tomcat, Oracle GlassFish, JBoss AS/WildFly, etc.
You should above all never manually copy/download/move/include the individual servletcontainer-specific libraries like servlet-api.jar, jsp-api.jar, el-api.jar, j2ee.jar, javaee.jar, etc. It would only lead to future portability, compatibility, classpath and maintainability troubles, because your webapp would not work when it's deployed to a servletcontainer of a different make/version than where those libraries are originally obtained from.
These links below will give you more information about this
How do I import the javax.servlet API in my Eclipse project?
Understanding who provides servlet-api.jar, is it web-container or part of Java EE download
http://wiki.metawerx.net/wiki/JARFilesYouShouldNeverIncludeInYourWebapp
I am running Eclipse with Tomcat 5.5.
My dynamic web site project includes some JAVA code that needs external jar files. Where should I place those jar files so Apache will not giving me errors such as java.lang.ClassNotFoundException ?
Thanks on this.
Put them in the WEB-INF/lib of your web context, of course.
If there are JDBC driver JARs in your project, you'll need to add those to the Tomcat server /lib for Tomcat 7 and higher. Those should not be in your WEB-INF/lib.
Make sure that the jar you want to use(WebContent/WEB-INF/lib/yourjar) is visible in Eclipse. (Here)
When I used the windows file explorer to add the jdbc jar to my project it wasn't visible in Eclipse and the error ClassNotFoundException kept coming. However, dragging the jar into the Eclipse(UI) project did work for me.