Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 880
Zuned Ahmed Avatar asked Apr 17 '12 09:04

Zuned Ahmed


People also ask

How do I add a class file to an existing war?

class file is part of a Jar file, you can place the new version of the Jar file directly in application_root/module_name/WEB-INF/lib.” In Example. war file ,the WEB-INF/lib contains only three jar files(mysql-connector-java-5.0.

Can a war file contain another war file?

Typically, war files don't contain war files. They can contain jar files; that's what the directory WEB-INF/lib is for.

How do I change a class file in a war file?

Make required changes, compile one particular file into class with all dependency/classes in place and finally replace the class file. Finally restart the container. Once war is exploded file will not be replaced. Save this answer.


1 Answers

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. But the best to make a separate jar module out of it.

like image 97
khmarbaise Avatar answered Sep 28 '22 05:09

khmarbaise