How to add an external banner to the maven webapp project

I have a Spring roo project (basically a maven project). I want to add dropbox sdk to the project, the problem is not maven. I added the following files

<dependency> <groupId>com.dropbox</groupId> <artifactId>dropbox-sdk</artifactId> <version>1.3.1</version> <scope>system</scope> <systemPath>${project.basedir}/libs/dropbox-java-sdk-1.3.1.jar</systemPath> </dependency> 

He solved the compilation error, but when I run the project in the Spring Tool Suite, the jar files are not added to the war lib folder. How to make maven add my external jar files to my war lib folder?

I do not want to install jar in maven, since I have to install it on all machines that use the project

+6
source share
7 answers

I finally found a neat solution that is much easier to implement. You add an in-project repository inside a java project and link to it in pom.

You add the in-project repository to maven as follows:

 <repository> <id>in-project</id> <name>In Project Repo</name> <url>file://${project.basedir}/libs</url> </repository> 

Then create a folder structure in the root folder of your project that looks something like this:

 /groupId/artifactId/version/artifactId-version.jar 

and add the dependency as usual.

This approach has the least amount of code and work required, and if this library is ever added to the maven repository, you can always delete your repository in the project.

http://bit.ly/OGVHSN

+12
source

I recommend creating a “third party” repository on a Maven repository server, such as Nexus or Artifactory, and upload the jar there. Despite the fact that this means that the banner in Maven, at least with the repository server, is available to everyone who will create your application.

+2
source

I do not recommend this approach, but you can add some POM configuration to install third-party dependencies in a separate profile:

 <profiles> <profile> <id>install-dependencies</id> <build> <plugins> <plugin> <artifactId>maven-install-plugin</artifactId> <version>2.3.1</version> <executions> <execution> <id>install-dropbox-sdk</id> <phase>validate</phase> <goals> <goal>install-file</goal> </goals> <configuration> <groupId>com.dropbox</groupId> <artifactId>dropbox-sdk</artifactId> <version>1.3.1</version> <file>src/main/lib/dropbox-java-sdk-1.3.1.jar</file> <packaging>jar</packaging> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile> <profile> <id>build</id> <activation> <activeByDefault>true</activeByDefault> </activation> <dependencies> <dependency> <groupId>com.dropbox</groupId> <artifactId>dropbox-sdk</artifactId> <version>1.3.1</version> </dependency> </dependencies> </profile> </profiles> 

There are two profiles here: install-dependencies and build . The first installs the dropbox-sdk dependency in your Maven repository and should be run once on each computer as follows:

 mvn -Pinstall-dependencies validate 

The second is enabled by default and adds the Dropbox SDK as a dependency.

To be honest, this is not much better than starting

 mvn install:install-file -Dfile=src/main/lib/dropbox-java-sdk-1.3.1.jar -DgroupId=com.dropbox -DartifactId=dropbox-sdk -Dversion=1.3.1 -Dpackaging=jar 

on each machine.

Another drawback of this approach is that you will have to add all the dropbox-sdk dependencies to your assembly, whereas if you do it right by adding JAR and POM to the repository server, Maven will correctly calculate the transitive dependencies.

+2
source

The best way to solve this problem is to add these local jar files to the WEB-INF / lib folder. Then you will find all these jars packaged in your latest war file.

+1
source

I know that I'm very late, but I was wondering why you do not put the jar in the local repo in the .m2 file and add the link to the pom from there?

0
source
  • change the lib path to: SRC / Main / WebApp / WEB-INF / Library

  • in pom.xml:

    <systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/xxxx.jar</systemPath>

0
source

There is a much simpler solution that installs webResource in the plugin. By decision, you can add any local disk files to the war! An example as shown below

  <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <warName>api</warName> <webResources> <resource> <directory>libs/</directory> <targetPath>WEB-INF/lib</targetPath> <includes> <include>**/*.jar</include> </includes> </resource> </webResources> </configuration> </plugin> 
0
source

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


All Articles