Java restful services as dependence on war from war

I have two different maven modules in the project, one of which is a ui module with angular js stuff and one service module that has soothing web services with knitwear. My question is here: is there anyway I can add this service module depending on the ui module in pom.xml and use it from the ui module as a service. The idea here is not to launch them as different wars, but as one.

+5
source share
2 answers

You can create your service module as a 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 the libs folder in your main project and place the created JAR file there. The main pom.xml project 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> 
+1
source

This is what I did in my small projects,

1. First, create an empty project that acts as a container / parent for the components and projects of the user interface and services using the tags tag. You indicate in it as module . You can call it APP.

To create a project, you create an APP, which in turn builds both modules and deploys the APP to the server.

This is just an empty Maven project with only pom.xml

Specify packaging as war in pom.xml

2. Specify the service project as dependency for the user interface project.

3. Specify the APP project as parent both in the service and in the user interface project.

Hope this helps!

0
source

Source: https://habr.com/ru/post/1257628/


All Articles