Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add external library .jar to Spring boot .jar internal /lib

I have an external .jar that cannot be imported from public repositories using pom.xml, it's sqljdbc41.jar.

I can run the project locally from my IDE, and everything will work. I referenced the library after downloading it like so:

<dependency>     <groupId>com.microsoft.sqlserver</groupId>     <artifactId>sqljdbc41</artifactId>     <version>4.1</version>     <scope>system</scope>     <systemPath>${basedir}/lib/sqljdbc41.jar</systemPath> </dependency> 

When I run mvn clean package to create my .jar file and try to run the created .jar, a mistake will pop up, which mentions the SQL Server references are not valid. I then extracted my .jar file and true enough, everything that is referenced in the pom.xml file properly gets downloaded and added, however, my SQL Server does not.

I can, in a very hacky way* just manually add the sqljdbc41.jar to my /lib folder after it's been compiled as a .jar, and it'll work, however that seems highly unoptimal. What would be a better approach?


*Opening the .jar file with Winrar, going to the /lib folder, manually selecting my sqljdbc41.jar file, then make sure to select the No Compression option bottom left where Winrar gives you compression options, in case you find this by Google and no one answered.

like image 666
Erick Avatar asked May 13 '15 07:05

Erick


People also ask

How do I create a JAR file with an external library?

You can right-click on the project, click on export, type 'jar', choose 'Runnable JAR File Export'. There you have the option 'Extract required libraries into generated JAR'.


1 Answers

you can set 'includeSystemScope' to true.

<plugin>   <groupId>org.springframework.boot</groupId>   <artifactId>spring-boot-maven-plugin</artifactId>   <configuration>     <includeSystemScope>true</includeSystemScope>   </configuration> </plugin> 
like image 108
allen Avatar answered Oct 17 '22 09:10

allen