https://kotlinlang.org logo
#ktor
Title
# ktor
r

Rafał Kuźmiński

10/23/2023, 11:51 AM
Hello. After Tomcat upgrade from 9.x to 10.x all Ktor services are crashing with
"NoClassDefFoundError: javax/servlet/http/HttpServlet"
and
Error instantiating servlet class [io.ktor.server.servlet.ServletApplicationEngine]
Do I need to change some settings in web.xml?
e

e5l

10/23/2023, 11:52 AM
Hey! Could you tell me what ktor dependency you’re using for tomcat?
r

Rafał Kuźmiński

10/23/2023, 11:58 AM
For development purposes we are using Netty, so we didn't need any dependency for tomcat. We are only using War task to build .war file which is send to Tomcat on production
e

e5l

10/23/2023, 11:59 AM
Could you tell me if you’re using any ktor servlet dependency?
r

Rafał Kuźmiński

10/23/2023, 12:00 PM
Sure, I'll check. Its a big project with many custom dependencies, so I'll need a minute
🙏 1
We use only "io.ktorktor server servlet2.2.1"
I searched ktor docs for "servlet" and I think I found solution. For newer tomcat I need to include "io.ktor:ktor-server-servlet-jakarta" right?
e

e5l

10/23/2023, 12:15 PM
Yep! The new version is supported with a different module for backward compatibility. Could you try it? 🙂
r

Rafał Kuźmiński

10/23/2023, 12:41 PM
Yes, it is working in Tomcat 10, but I see that it has no backwards compability? On Tomcat 9 jakarta is crashing, so we have to update Tomcat and all wars in the same time?
e

e5l

10/23/2023, 12:43 PM
You can try updating it in a module-by-module way
r

Rafał Kuźmiński

10/23/2023, 12:44 PM
Could you elaborate? I have 5 applications working on servlet and Tomcat 9. We need to update Tomcat to version 10, is there any way to do code changes on old Tomcat and then just replace Tomcat?
e

e5l

10/23/2023, 12:46 PM
It depends on how the project is structured. If they all in a different modules, you can try make per-module update. Otherwise, you can try adding both dependencies. It will need to explicitly specify imports depending on the version of tomcat is used by specific app
r

Rafał Kuźmiński

10/23/2023, 12:48 PM
All the apps are on the same server and same single instance of Tomcat, so I don't know how to change just one of them. Adding both dependencies should work on Tomcat 9 and Tomcat 10? Because I also need to change configuration in web.xml
Maybe we will try to create two instances of Tomcat and try to migrate with it. Any way, thanks for help, I ll try to figure this out
e

e5l

10/23/2023, 12:49 PM
Splitting is a good idea! I’m not sure if it will work on a single instance