1

I had two jars in resources folder with that i build my project to jar(say editor.jar) using maven. My class File Does not have dependencies to this jars while at building.

But When i run the editor.jar using command java -jar editor.jar it needs the any one of jar in the lib folder as its dependency.

so i need to add these to jar into the classpath . i read in the same webesite in this question : but it is not worked for me.

My directory looks like this:

what i done so far in my pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>editor</groupId>
    <artifactId>editor</artifactId>
    <version>1.0-SNAPSHOT</version>

    <build>
        <finalName>editor</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>Jdbc</mainClass>
                        </manifest>
                        <manifestEntries>
                            <Class-Path>lib/*.jar</Class-Path>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

How to add the two jars to classpath and make execute the editor.jar ?

James Z
  • 12,209
  • 10
  • 24
  • 44
Dhanasekaran Don
  • 294
  • 1
  • 14
  • Not sure about this approach but why don't you try to specify these 2 dependencies in your pom.xml and then later let maven have these jars fetched for you instead of you manually having to add these jars there and then specifying the classpath for it in the `pom.xml`? You can try this atleast... – robot_alien Jun 20 '18 at 09:17
  • @robot_alien I not pointing towards maven central repository . I'm using other repository it doesn't contains these two jars – Dhanasekaran Don Jun 20 '18 at 09:25
  • Are you using a repository manager? If not I strongly recommend to use one... – khmarbaise Jun 20 '18 at 10:38

1 Answers1

0

try to add <Class-Path>resources/lib/*.jar</Class-Path>in your pom.xml file

Ak S
  • 97
  • 1
  • 8