2

I am using Maven to manage my dependencies and am trying to pull a few, proprietary, jar files from my project directory. (Yes, I know, I'm a crazy idiot who doesn't get the purpose of Maven and should never do this.) On compilation, I get the typical warnings about pointing to files in my project directory. However, the specified jar files are not placed in my .m2 directory, and thus, the project does not compile as dependencies are missing.

In pom.xml:

<dependency>
<groupId>org.sample</groupId>
<artifactId>sample</artifactId>
<scope>system</scope>
<version>2.0.3</version>
<systemPath>${project.basedir}/WebContent/WEB-INF/lib/my_file.jar</systemPath>
<type>jar</type
<optional>true</optional>
</dependency>

Question is, am I declaring my groupId and artifactId correctly? Is there a way to force Maven to use several, random, jar files in my project directory?

Thanks for the help.

schweeb
  • 31
  • 4

2 Answers2

1

You have to add the jar in your classpath as well for mvn to pickup your system dependencies. <Class-Path>libs/my_file.jar</Class-Path>

Plugin Config

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>${maven.jar.plugin.version}</version>
    <configuration>
        <archive>
            <manifestEntries>
                <Build-Jdk>${jdk.version}</Build-Jdk>
                <Implementation-Title>${project.name}</Implementation-Title>
                <Implementation-Version>${project.version}</Implementation-Version>
                <Specification-Title>${project.name} Library</Specification-Title>
                <Specification-Version>${project.version}</Specification-Version>
                <Class-Path>libs/my_file.jar</Class-Path>
            </manifestEntries>
            <manifest>
                <addClasspath>true</addClasspath>
                <mainClass>com.app.MainClass</mainClass>
                <classpathPrefix>libs/</classpathPrefix>
            </manifest>
        </archive>
    </configuration>
</plugin>
Amith Kumar
  • 4,400
  • 1
  • 21
  • 28
1
<repositories>
    <repository>
        <id>my-local-repo</id>
        <url>file:///${project.parent.basedir}/dependencies/lib</url>
    </repository>
</repositories>

regardless you can add maven plugin to copy the depdencies from m2 to the same directory with this plugin

    <plugin>
                            <artifactId>maven-dependency-plugin</artifactId>
                            <executions>
                                <execution>
                                    <phase>install</phase>
                                    <goals>
                                        <goal>copy-dependencies</goal>
                                    </goals>
                                    <configuration>
                                        <copyPom>true</copyPom>
<!--                                        <addParentPoms>true</addParentPoms>-->
                                        <outputDirectory>${project.basedir}/../dependencies/lib/</outputDirectory>
<!--                                        <useSubDirectoryPerArtifact>true</useSubDirectoryPerArtifact>-->
                                        <useRepositoryLayout>true</useRepositoryLayout>
                                    </configuration>
                                </execution>
                            </executions>
                        </plugin>
                    <plugin>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <version>3.3.0</version>
                        <configuration>
                            <descriptors>
                                <descriptor>repository.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </plugin>
Hard Worker
  • 995
  • 11
  • 33