Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java restful services as jar dependency on a war

I have two different maven modules in a project, one is ui module with angular js stuff and one services module which has restful web services with jersey. My question here is, Is there anyway i can add this services module as dependency to ui module in the pom.xml and use it from ui module as a service. Idea here is to not deploy both as different wars, but as one.

like image 297
Nikhil Avatar asked Nov 08 '22 08:11

Nikhil


1 Answers

You can generate your services module as JAR. pom.xml should contain:

<packaging>jar</packaging>

And

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
    </configuration>
    <executions>
        <execution>
            <id>make-assembly</id>
            <phase>install</phase>
            <goals>
                <goal>single</goal>
        </goals>
        </execution>
    </executions>
</plugin>

Create libs folder in your main project and place there generated JAR file. Main project pom.xml should contain:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-install-plugin</artifactId>
        <version>2.5.2</version>
        <executions>
            <execution>
            <id>install-external</id>
            <phase>clean</phase>
            <configuration>
                <file>${basedir}/libs/your_service.jar</file>
                <repositoryLayout>default</repositoryLayout>
                <groupId>your_service</groupId>
                <artifactId>your_service</artifactId>
                <version>1.0</version>
                <packaging>jar</packaging>
                <generatePom>true</generatePom>
            </configuration>
            <goals>
                <goal>install-file</goal>
            </goals>
            </execution>
        </executions>
    </plugin>

And

<!-- External lib -->
<dependency>
    <groupId>your_service</groupId>
    <artifactId>your_service</artifactId>
    <version>1.0</version>
    <!-- <systemPath>${basedir}/libs/your_service.jar</systemPath> -->
    <!-- <scope>system</scope> -->
</dependency>
like image 133
Justinas Jakavonis Avatar answered Nov 14 '22 22:11

Justinas Jakavonis