1

I'm very new to maven, so kindly bear with me.

i have a maven project with almost 100 dependencies all of which are present in my local system. So I'm adding them to my classpath via pom.xml with <scope> being system and <systemPath> giving path to the said dependencies. A rough structure of my pom.xml looks like this:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com</groupId>
    <artifactId>MAVEN_APP</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>MAVEN_APP</name>
    <properties>
        <jdk.version>1.8</jdk.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>jar1</groupId>
            <artifactId>dependency1</artifactId>
            <version>0.9.5</version>
            <scope>system</scope>
            <systemPath>path/to/directory/outside/project/directory/jar1Name.jar</systemPath>
        </dependency>
        ......
        <dependency>
            <groupId>jar100</groupId>
            <artifactId>dependency10</artifactId>
            <version>1.9.7</version>
            <scope>system</scope>
            <systemPath>path/to/directory/outside/project/directory/jar10Name.jar</systemPath>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

This includes all the jars into my classpath and everything is running fine.

But i would like to keep the path/to/directory/outside/project/directory/ inside my app.propeties file and pom.xml should fetch this path from the properties file.

Is there a way in maven to do this.

Could somebody help me here. Thanks in advance.

Phillip
  • 437
  • 1
  • 5
  • 16
  • Why? maven is collecting the jars from their location on you system into the "distribution target" in the *package* phase. not needing to deal with the dependencies location withing you app is the major benefit of maven... – Timothy Truckle Feb 01 '18 at 13:46
  • @TimothyTruckle: All my dependencies are in a lib folder which is present outside the project directory.Currently i have to mention the path explicitly for all my 100 dependencies(not an easy task). By mentioning path in properties file, pom will take the path from properties file and replace it in pom.xml. So at a later time if location of my lib folder changes, i only need to change the path at my properties file and maven will take care of the rest – Phillip Feb 01 '18 at 13:51
  • Please see https://stackoverflow.com/questions/849389/how-to-read-an-external-properties-file-in-maven – Babl Feb 01 '18 at 13:53
  • @Babl: I did but all plugin links are dead now. – Phillip Feb 01 '18 at 13:59
  • 1
    @Edward what do you mean dead? The link to http://www.mojohaus.org/properties-maven-plugin/ is still available and the plugin is still supported. – Babl Feb 01 '18 at 14:00
  • @Babl: ` org.codehaus.mojo properties-maven-plugin 1.0.0 initialize read-project-properties ${project.basedir}\app.properties ` – Phillip Feb 01 '18 at 14:07
  • Gives me following error: `cannot read lifecycle mapping metadata, error in opening zip file` – Phillip Feb 01 '18 at 14:09
  • Try to remove the plugin from your local maven repository and force downloads from remote by adding -U command line argument. Seems the plugin jar is corrupted ... – Babl Feb 01 '18 at 14:14
  • @Babl: I deleted the jar. Could you mention how to do the force download in eclipse. I'm fairly new to maven – Phillip Feb 01 '18 at 14:23
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/164349/discussion-between-babl-and-edward). – Babl Feb 01 '18 at 14:24
  • First put all your jar files into a repository manager use it from there. Than you can change your dependencies into usual dependencies. And that's it...Furthermore adding the jar plugin like you did in your pom is wrong, cause it's bound already by the life cycle which is the default which in your case is the jar life cycle... – khmarbaise Feb 01 '18 at 21:55

0 Answers0