Search code examples
javamavenmaven-pluginmaven-3

how to use class file from another war


We have two different web application and we want to extend few controllers of one war into another war.

We are using maven to build the project.

to include war we have given its dependency as

<dependency>
            <groupId>com.abc.exchange</groupId>
            <artifactId>employer</artifactId>
            <version>2.3.M2-SNAPSHOT</version>
            <type>war</type>
            <scope>compile</scope>
        </dependency>

It is unable to build giving class not found exception.

Can any body help me out how to achieve this?

I am getting error maven build failed :

[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project agent-war: Compilation failure: Compilation failure:
[ERROR] \projects\trunk_new\agent\src\main\java\com\platform\agent\web\AgentEmployeeController.java:[22,41] cannot find symbol
[ERROR] symbol  : class EmployeeController
[ERROR] location: package com..platform.employer.web

Solution

  • You can define the war plugin to produce a separate jar file which is available via a classifier based on the configuration:

    <configuration>
      ...
      <attachClasses>true</attachClasses>
      <archiveClasses>true</archiveClasses>
    </configuration>
    

    After that you can use this as a separate dependency in other projects by adding <classifier>classes</classifier> to the dependency reference. But the best to make a separate jar module out of it.