Jswq
Jswq

Reputation: 776

How to package spring-boot to jar with local jar using maven

I have a jar in my system, and I want to package it into jar application using maven, my dependency and plugin as below:

       <dependency>
            <groupId>org.wltea</groupId>
            <artifactId>IKAnalyzer</artifactId>
            <version>3.2.3</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/src/main/BOOT-INF/lib/IKAnalyzer3.2.3Stable.jar</systemPath>
        </dependency>


    <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                    <configuration>
                        <mainClass>gpdi.MyApp</mainClass>
                    </configuration>
                </execution>
            </executions>
        </plugin>

I also try maven-dependency-plugin but did'nt work when packaging jar file.

   <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/${project.build.finalName}/BOOT-INF/lib</outputDirectory>
                        <includeScope>system</includeScope>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Upvotes: 0

Views: 3105

Answers (1)

Nadendla
Nadendla

Reputation: 722

Add the below plugin and clean your project :

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-install-plugin</artifactId>
    <executions>
        <execution>
            <id>install-Transformation lib</id>
            <phase>clean</phase>
            <configuration>
                <file>${basedir}/file/path/jarname.jar</file>
                <repositoryLayout>default</repositoryLayout>
                <groupId>org.wltea</groupId>
                <artifactId>IKAnalyzer</artifactId>
                <version>3.2.3</version>
                <packaging>jar</packaging>
                <generatePom>true</generatePom>
            </configuration>
            <goals>
                <goal>install-file</goal>
            </goals>
        </execution>
    </executions>
</plugin>  

Once you clean the project. Comment scope and systempath like below then build and install :

<dependency>
    <groupId>org.wltea</groupId>
    <artifactId>IKAnalyzer</artifactId>
    <version>3.2.3</version>
    <!--scope>system</scope>
    <systemPath>${project.basedir}/src/main/BOOT-INF/lib/IKAnalyzer3.2.3Stable.jar</systemPath-->
</dependency>

Upvotes: 2

Related Questions