I am facing this exception on tomcat server startup.
Here I am using javax.servlet-api-4.0.1.jar in my project, and I included this for runtime also.
But when I deploy my application into tomcat 8.5, tomcat picks the older jar servlet-api from its /lib folder.
I know this method setSessionTimeout is included in servlet 4.0, but how will I direct tomcat to pick jar from my project's WEB-INF/lib folder instead of tomcat/lib.
I tried to place servlet-api-4.0 jar into tomcat/lib and deleting older jar, then project starts properly. But is it the correct way? Can't tomcat pick the latest jar from my project's lib directory.
Please help.
Do not bring your own servlet API jar.
You claim you're using Tomcat 8.5, which implements servlet spec 3.1. Bringing along a newer jar will not magically make it implement this newer spec.
If you want 4.0, use Tomcat 9. And don't bring your own servlet API. The version that ships with Tomcat is perfectly fine. Depending on the way you build, you need some version of it at build time, but you do not package it for runtime use (e.g. Maven calls it "provided", in gradle I see "compile" or "compileOnly")
Related
I am running a web application using Tomcat, JDK8 and Netbeans IDE (using ANT for build and IVY for dependency management).
I currently place JARs that need to be available to the JRE (servlet-api.jar, jsp-api.jar, el-api.jar, tomcat-dbcp.jar) in JAVA_HOME/jre/lib/ext.
I'm upgrading to a new JDK version (JDK17), which no longer has the JRE extensions folder. I'm wondering where I should place these JARs.
According to this post (and others I've seen), it is better practice to use a dependency manager and add these jars to your classpath anyway.
I currently use IVY to manage my dependencies and have customized my ANT build to add run-time dependencies to the WEB-INF/lib folder of the built WAR file.
However, I do not need the JARs I listed above to be available to my application at runtime, I need them to be available to the JRE. That is, I do not want the JARs (servlet-api.jar, etc.) to be in WEB-INF/lib of my built WAR file.
How can I do this?
Sharpening my final questions:
How can I make certain JARs/dependencies available to the JRE in Netbeans in my development environment?
How can I make certain JARs/dependencies available to the JRE in the built WAR file used on my production environment?
Am I correct in saying that these JARs need to be available to the JRE? All of the posts I've seen discuss compile-time vs run-time dependencies but it seems the case I'm describing is a different category of dependency. Is this correct?
I currently place JARs that need to be available to the JRE (servlet-api.jar, jsp-api.jar, el-api.jar, tomcat-dbcp.jar) in JAVA_HOME/jre/lib/ext.
That's not the best way to do things. See Is putting external jars in the JAVA_HOME/lib/ext directory a bad thing?
Note that the jre/lib/ext mechanism has been removed from newer versions of Java, so this will not work anymore if you use a newer version of Java. (This has been removed in JDK 9).
However, I do not need the JARs I listed above to be available to my application at runtime, I need them to be available to the JRE.
Why?
That is, I do not want the JARs (servlet-api.jar, etc.) to be in WEB-INF/lib of my built WAR file. How can I do this?
Why not? Putting the dependencies that your application needs in WEB-INF/lib is the normal thing to do in Java web applications. Why do you want to do things the non-standard way?
But: Some JAR files, such as servlet-api.jar, jsp-api.jar and el-api.jar are not supposed to be included in your application. Those JAR files define standard Java EE / Jakarta EE APIs and will be provided to your application at runtime by the application server (Tomcat, etc.) that you deploy your WAR file in.
You can add those JAR files as dependencies using Maven with provided scope, which means they will be used while compiling, but won't be packaged into your application.
Am I correct in saying that these JARs need to be available to the JRE?
No, those JARs do not need to be available to the JRE. JAR files that contain standard APIs will be provided by your Java EE / Jakarta EE container at runtime. Other JAR files should be included in your application in WEB-INF/lib.
Background-I am trying to deploy a custom jar to the Tomcat 8.x lib("${catalina.home}/lib") folder. Per Tomcat documentation, it should be picked up when the server starts(via common classloader), and classes(from the jar) are made available to Tomcat and other apps deployed on it. However, I have an app deployed on Tomcat which is looking for the classes from this jar, but it fails with NoClassDef found error.
What I have done so far- I have tried to look at the classes deployed by using -verbose:class but am unable to find the class(es) from the jar. It appears that tomcat ignored the custom jar(yes- I understand all the classes are not loaded at the startup rather they can be 'found' using delegation pattern at runtime). To test that tomcat is working per documentation ie autoload from 'lib' folder, I threw in the ojdbc.jar in the same lib folder. Voila- I could see it loading some classes from the ojdbc jar(at this stage,my code doesn't need ojdbc.jar or classes from it).
Need help -- I am unable to understand why tomcat is ignoring my custom jar, while it deploys ojdbc.jar(at a theoretical level it is also custom as it is not bundled with tomcat) ?
I have a project which in the meantime runs locally on Tomcat but I'm planning to deploy to some server in the future.
I have a few questions:
I'm using tomcat-jdbc.jar. How should I include that jar in the project? copy it to WEB-INF/lib or add a library reference to tomcat? is the latter portable? Can I use this jar even if the server I'm deploying to is using jetty?
When I added the JRE, eclipse asked me to point it to the JRE path. The line that was added in the classpath was
classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"
How does eclipse figure out from this line where the JRE is at?
When the project is deployed to the server, how would the project hierarchy look like?
My guess is:
<project name>
----<build> (.class files)
----<WebContent>
--------<META-INF>
------------MANIFEST.MF
--------<WEB-INF>
------------<lib>
----------------external_jar.jar
------------web.xml
---------index.html
Is this correct? if so, how will the runtime know where to find the JRE? or the tomcat-jdbc.jar which is in the Tomcat installation folder?
Your application needs the following three types of "resources"
System Resources: JRE classes, some extensions/libraries provided by the server you deploy on.
Your dependencies: Any libraries you use, say common-utils, poi etc. These JAR files go in your web-inf/lib folder
Your classes. These are deployed with the WAR file at web-inf/classes
So, to answer your questions:
If you are deploying to Tomcat, the tomcat-jdbc.jar will be provided. Take care of the version though. If your prod server will be tomcat but dev is say Jetty, then you need to provide this jar in your local IDE, but not export it in the WAR file. But if you are developing on tomcat and say deploying on some other server, then this jar has to be bundled with your war file (web-inf/lib folder). Dev and Prod servers need not be same, but take care of the JRE version and dependency on Prod server provided libraries.
JRE is a configurable setting for your server and also your IDE (Eclipse)
Project hierarchy is correct, but you will most probably deploy as WAR file, so your build folder is exported in web-inf/classes. You can verify by opening the WAR file with any zip editor.
Regarding the portability of tomcat-jdbc.jar
Unfortunately this depends on the tomcat library and version. There might be more dependencies of this jar file which might cause problems later on. I would recommend not relying on this jar unless you plan to deploy on tomcat.
you should test your application with the same server you're going to use in production.
to see and set the jre properties eclipse->preferences->java->Installed JREs.
If you export a war file, all files in WebContent will be in the war and the .class files from src folder will be in WEB-INF/classes.
When you uses a server like tomcat, it uses the configuration you setted on it.
If you want the application to always reference your jar, put it in the web-inf lib.
As Daniel has mentioned below,eclipse gets the JREs from the installed JREs under the preferences tab. You can have multiple JREs installed and configured in your eclipse and then select individually for a project and also select default.
3.Your project hierarchy is correct. The runtime will get the JRE from the JAVA_HOME environment variable set on the server.
1) Pool connections, it's a service provided by Application Server (Tomcat in this case). IMHO you have to avoid bind your application with specific implementation, in that case use generic javax.sql.DataSource for expample, and then "inject" or lookup the implmementation from the server. Then if you use Jetty, configure what you want as connection pool implementation https://wiki.eclipse.org/Jetty/Howto/Configure_JNDI_Datasource
So dont´t include in your web-inf/lib tomcat-jdbc.jar.
2) The "org.eclipse.jdt.launching.JRE_CONTAINER" it's a internal variable of eclipse and the value is what you configure on eclipse properties. It's used for eclipse to compile and run your app.
3) in your project structure ".class" files, must go in "WEB-INF/classes". That it's defined by servlet specification. Eclipse automatically generate the correct structure if you select yor project and with right click run "Export" --> "War file". Or you can use maven.
I've build a spring-based web project in Eclipse using Maven. Dependencies and class path are correct and the deployment assembly also lists spring-web*.jar correctly. However, when I deploy it using WebSphere 8 from within Eclipse the mentioned JAR file is missing from the created libs folder under .metadata.plugins\org.eclipse.wst.server.core\tmp2*\WEB-INF\lib . This JAR however is listed under the module section as a submodule for the container. I wasn't able to find out, why this JAR is listed there and why it is not copied to the LIB folder.
It works with a Tomcat server, it works when I export the WAR and deploy it manually and it also works when I manually copy the JAR to the lib folder.
Q1: Is this specific to Websphere?
Q2: Why is SPRING-WEB listed as submodule and what effect has this?
Q3: How can I automatically deploy it correctly?
This seems to be a bug in WAS as reported here
You can either copy the missing JARs manually or you can use the "Run server with resources on server" option in the "Publishing settings for WebSphere Application Server" server settings.
I downloaded the zip version of Glassfish 3.1.2.2 and unzip it in my local directory.
When I try to add the following glassfish directory as a runtime library, it says there is no glassfish runtime.
I checked out the folder and I think it is missing some jsf jar such as jsf-impl..
How do I set this up? DO I really need to download some 3rd party jsf implmentation jars?
Thanks
I checked out the folder and I think it is missing some jsf jar such as jsf-impl.
The two JARs jsf-api.jar and jsf-impl.jar have since Mojarra 2.1.6 been merged into a single JAR javax.faces.jar. This was done so to be in line with general Java EE Maven rules. See also issue 2028.