My project compiles fine in IntelliJ, it is a simple spring-mvc written in scala.
I get this error when I run it using tomcat:
java.lang.NoClassDefFoundError: org/example/houses/SomeClassNameHere
The above isn't the exact name of my library.
My controller looks like:
package com.example.scalacms.web.controllers
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.{ResponseBody, RequestMapping}
import org.example.house
@Controller
class HomeController {
var houses: Houses = _
@RequestMapping(Array("/"))
@ResponseBody
def index: String = {
"hello, world!"
}
}
I'm confused because it compiles fine in IntelliJ, it picks up all my classes in intellisense etc.
Could it be that tomcat doesn't have the library in my classpath? I am using an exploded artifact.
I can't see the classpath anywhere in the output windows so I cannot confirm.
Update
So I looked in the /out/artifacts/myapp_web_war_exploded/WEB-INF/lib
and I don't see the jar file there. Why is the jar not being included in the deployment? What should I do to have it included in intellij?
If it's a maven WAR project, check if the jar is marked as excluded or in scope provided
in the pom, as any of those would remove the jar from the WAR.
If it's not the case, go to the command line to the directory where the pom WAR is, and do a mvn dependency:tree
and confirm that your jar is indeed there.
If the jar is there, then it means it can only be an IDE related problem. Try the following steps:
i dont know in intellij but in eclipse when you deploy and work with maven it sometimes occurs that you not include your maven dependencies in your deployment assembly
look this :Maven dependencies not visible in WEB-INF/lib
I had the same problem and fixed it now after debugging ...
IntelliJ usually auto-creates a folder /lib under your /src folder inside your project, and then it would tell your project that all LIBs are in there, on that basis; we usually assume that it's the place to put all your LIBs in there as well.
Although with that setup your project would compile fine since IntelliJ can link up to your JARs However, with that sort of setup Tomcat will fail to execute, since Tomcat expects to find the classes under /WEB-INF/lib,...
Therefore, the solution is to:
1) Drag your LIB folder (sorry I mean "/lib") from /src/lib to be under /web/WEB-INF directory
2) You would get a warning about moving classes / JARs, say YES.
(You need to tell your project to re-map your existing pre-defined LIBs to the new folder):
3) From the main menu, select FILE -> Project Structure
4) Select Libraries from the left menu
5) If you don't see any existing libs, then you're done, click OK
6) If you do see libs in there, then:
7) Click on each LIB from the middle-list, and then remove the ones that can't be located,
8) Re-add them again from the new location
9) Repeat (7) to all other LIBs.
10) OK,
RE-compile, your project should deploy on Tomcat now and work fine.
Regards Heider
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With