Including java libraries to Tomcat inside Eclipse - java

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.

Related

JAR libraries to TomCat

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.

java.lang.ClassNotFoundException: javazoom.spi.mpeg.sampled.file.MpegAudioFileReader [duplicate]

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.

Deploying a vaadin app to tomcat

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.

J2EE project with using classes from J2SE project [duplicate]

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.

jsf and eclipse setup. Lib in Explorer is different than lib in tomcat. How come?

I am starter in JSF2.0, and I have a question related to Eclipse (I am using Helios).
1)I create a Dynamic Project
2)I add JSF project facet.
3)I choose JSF user library (I have created it using MyFaces)
All ok so far.
I notice though that in the Project Explorer in WebContent/WEB-INF/lib the lib directory is empty instead of having MyFaces jars.
The application works fine though.
I looked into this and the jars are actually being placed in the corresponding lib directory of the app deployed under wtpwebapps of the Tomcat instance of eclipse in the .pluggins directory.
Ok, it works but IMHO it is incorrect to have the Project Explorer inconsistent with the directories actually deployed.
I.e. lib is shown empty in Project Explorer but with jars under wtpwebapps.
Am I wrong to dislike this inconsistency?
Is this how it should work or am I doing something wrong in the way I am setting my project?
Thanks!
That's normal for user-definied libraries. It's listed in libraries folder of the Java Resources folder. It's just an extra layer on managing libraries. If you dislike this, then choose Disable Library Configuration in the wizard and drop the JAR's in /WEB-INF/lib yourself.

Categories

Resources