Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven and adding JARs to system scope

Tags:

maven

I have a JAR in my Android project and I want it to be added to final APK. Okay, here I go:

    <dependency>         <groupId>com.loopj.android.http</groupId>         <artifactId>android-async-http</artifactId>         <version>1.3.2</version>         <type>jar</type>         <scope>system</scope>         <systemPath>${project.basedir}/libs/android-async-http-1.3.2.jar</systemPath>     </dependency> 

But when I am running mvn package I am getting a warning:

[WARNING] Some problems were encountered while building the effective model for **apk:1.0 [WARNING] 'dependencies.dependency.systemPath' for com.loopj.android.http:android-async-http:jar should not point at files within the project directory, ${project.basedir}/libs/android-async-http-1.3.2.jar will be unresolvable by dependent projects @ line 36, column 25 

And in the final APK there are no JARs.

How do I fix that?

like image 244
efpies Avatar asked Jun 07 '12 15:06

efpies


People also ask

What is system scope in Maven?

system This scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository. import (only available in Maven 2.0. 9 or later) This scope is only supported on a dependency of type pom in the section.

Where does Maven install Put JARs?

You can find your installed JARs and dependencies in your local repository. By default, you can find it here: Windows: C:\Users\USERNAME\. m2\repository.

Can we add external jar in Maven project?

Approach 2: Include jar as part of the maven project. In this approach you need to first create a folder in your maven project & add your external jar file. Once the jar file is added, include the jar file in your pom using following notation.


2 Answers

I don't know the real reason but Maven pushes developers to install all libraries (custom too) into some maven repositories, so scope:system is not well liked, A simple workaround is to use maven-install-plugin

follow the usage:

write your dependency in this way

<dependency>     <groupId>com.mylib</groupId>     <artifactId>mylib-core</artifactId>     <version>0.0.1</version> </dependency> 

then, add maven-install-plugin

<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}/lib/mylib-core-0.0.1.jar</file>                 <repositoryLayout>default</repositoryLayout>                 <groupId>com.mylib</groupId>                 <artifactId>mylib-core</artifactId>                 <version>0.0.1</version>                 <packaging>jar</packaging>                 <generatePom>true</generatePom>             </configuration>             <goals>                 <goal>install-file</goal>             </goals>         </execution>     </executions> </plugin> 

pay attention to phase:clean, to install your custom library into your repository, you have to run mvn clean and then mvn install

like image 80
Ging3r Avatar answered Sep 27 '22 21:09

Ging3r


You will need to add the jar to your local maven repository. Alternatively (better option) specify the proper repository (if one exists) so it can be automatically downloaded by maven

In either case, remove the <systemPath> tag from the dependency

like image 36
Attila Avatar answered Sep 27 '22 20:09

Attila