So I am trying to build a web application when a common jar needs to be shared between all web apps. So I built the pom.xml and put the JAR in the Tomcat/lib folder. Its dependency section looks like this (the artifact ID of this is web-common):
<dependencies>
<dependency>
<groupId>com.web.myapp</groupId>
<artifactId>web-application-configuration-files</artifactId>
<version>${project.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.web.myapp</groupId>
<artifactId>web-exceptions</artifactId>
<version>${project.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.web.myapp</groupId>
<artifactId>web-schema-files-jaxb</artifactId>
<version>${project.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/sshtools/j2ssh-core -->
<dependency>
<groupId>sshtools</groupId>
<artifactId>j2ssh-core</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jasypt/jasypt -->
<dependency>
<groupId>org.jasypt</groupId>
<artifactId>jasypt</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/javax/javaee-api -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jdom/jdom -->
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.opengis.cite.saxon/saxon9 -->
<dependency>
<groupId>org.opengis.cite.saxon</groupId>
<artifactId>saxon9</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.zookeeper/zookeeper -->
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.oracle/ucp -->
<dependency>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ucp</artifactId>
</dependency>
</dependencies>
Now the dependency section of my WAR file (artifact ID: access-controller) is something like this:
<dependencies>
<dependency>
<groupId>com.web.myapp</groupId>
<artifactId>web-common</artifactId>
<version>${project.version}</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.web.myapp</groupId>
<artifactId>web-application-configuration-files</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.web.myapp</groupId>
<artifactId>web-exceptions</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.web.myapp</groupId>
<artifactId>web-schema-files-jaxb</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-net/commons-net -->
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jasypt/jasypt -->
<dependency>
<groupId>org.jasypt</groupId>
<artifactId>jasypt</artifactId>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax/javaee-api -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jdom/jdom -->
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom</artifactId>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.python/jython -->
<dependency>
<groupId>org.python</groupId>
<artifactId>jython</artifactId>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.oracle/ojdbc6 -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.oracle/ucp -->
<dependency>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ucp</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
Both of these are linked via a parent project.
Now when I deploy the WAR on Tomcat. While running the application, it starts throwing all sorts of errors NoClassDefFoundError
, ClassNotFoundError
to LinkageError
, and everything under the sun of classes going haywire. Mostly it complains that it was not able to find classes from the dependencies I included. I can see all of them in the WAR's lib folder and entries in the MANIFEST file as well. First I started with the default scope (compile
), but since it starts throwing exceptions I had to make all the dependencies provided
and put them in the Tomcat/lib folder as well just to get it to work.
I think I must be doing something wrong, or is it the right way to go about it and is normal? I thought I read Maven well and good but it looks like there is a gap in my understanding somewhere.