javatomcatcompilationclasspathnoclassdeffounderror

NoClassDefFoundError when running app with external lib with Tomcat


I'm trying to run a project with Apache Tomcat 5.5. Since I don't have a pom.xml, and I need to use a Json library, I added that particular library to my dependencies (Project Structure -> Modules -> Dependencies) in IntelliJ, with "compile" scope. My IDE shows no errors or warnings and I can build the project just fine. However, when I run it with Apache Tomcat 5.5 (which is configured as follows)

<Context path="/EmblematicaHispanica" docBase="C:\Users\dantelo\IdeaProjects\emblematica-hispanica" debug="0">
<!-- EmblematicaHispanica -->
<Resource
    name="jdbc/J2EE-ExamplesDS"
    auth="Container"
    type="javax.sql.DataSource"
    factory="org.apache.commons.dbcp.BasicDataSourceFactory"
    driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost:3306/emblema?useSSL=false"
    username="..."
    password="..."
    maxActive="4"
    maxIdle="2"
    maxWait="10000"
    removeAbandoned="true"
    removeAbandonedTimeout="60"
    logAbandoned="true"
    validationQuery="SELECT 1"/>
</Context>

everything works fine, except where I call the function that uses that lib, where I get the following error:

java.lang.NoClassDefFoundError: org/json/JSONObject

I've been searching for a solution for a while but so far no luck


Solution

  • I just found the solution. It was way simpler than I thought. I copied the library from system explorer to the "lib" folder in web inf and now it works!