Question: I have a Spring Boot application and I have created a Jar out of that. Following is my `pom.xml`:

```
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-mail</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.thymeleaf.extras</groupId>
        <artifactId>thymeleaf-extras-java8time</artifactId>
        <version>2.1.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <!-- WebJars -->
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.7</version>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.6.2</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

```

I want to use this Jar in my other application so added this jar to my application. But when I am calling a method in that Jar, it is throwing a `ClassNotFoundException`.

How can I fix this issue? How can I add a dependency to a Spring Boot JAR?

Answer: 
Tunaki's answer is correct but doesn't work in **Spring Boot 2**.

### Spring Boot **1.x**

```
  <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>1.5.20.RELEASE</version>
    <executions>
      <execution>
        <goals>
          <goal>repackage</goal>
        </goals>
        <configuration>
          <classifier>exec</classifier>
        </configuration>
      </execution>
    </executions>
    ...
  </plugin>

```

[Read more](https://docs.spring.io/spring-boot/docs/1.5.20.RELEASE/maven-plugin/examples/repackage-classifier.html)

---

### Spring Boot **2.x**

> 
> If you are using `spring-boot-starter-parent`, the `repackage` goal is executed automatically in an execution with id `repackage`. In that setup, only the configuration should be specified as shown in the following example:
> 
> 
> 

```
  <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <executions>
      <execution>
        <id>repackage</id>
        <configuration>
          <classifier>exec</classifier>
        </configuration>
      </execution>
    </executions>
    ...
  </plugin>

```

[Read more](https://docs.spring.io/spring-boot/docs/2.1.4.RELEASE/maven-plugin/examples/repackage-classifier.html)
any project if you want add as a dependency you need that project `<groupId>`,`<artifactId>`,`<version>`, with these details you can add your project as a dependency in another module or application
for ex: your application pom details

```
<project 
        <groupId>com.sample</groupId>
        <artifactId>sampleapp</artifactId>
        <version>1.0</version>
        <packaging>jar</packaging>
</project>`

```

your dependency as like below

```
 <dependency>
 <groupId>com.sample</groupId>
 <artifactId>sampleapp</artifactId>
 <version>1.0</version>
</dependency>

```