when i convert my spring boot program as jar file and used thar jar file in another project i got error in repository - spring

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "com.proretention.repository.LogRepository.save(Object)" because "this.logRepo" is null
at com.proretention.service.LogService.save(LogService.java:27)
at com.proretention.logger.LoggerTestApplication.main(LoggerTestApplication.java:20)

This probably happens because your jar file only contains the classes of your project. You have to create a 'fat jar' which is a jar that also contains the dependencies of your project. If you are using Gradle the output of the 'bootJar' task is what you are looking for.
The 'jar' task creates a plain jar with the following name inside build/libs: "PROJECTNAME-0.0.1-SNAPSHOT-plain.jar" while the 'bootJar' task creates one with this name "PROJECTNAME-0.0.1-SNAPSHOT.jar", this is the one you need.

Related

After creating JAR using "maven-jar-plugin" along with "*.Properties"(files), methods from JAR are failing as "*.properties" path is changed

create JAR from maven project, along with all dependable properties files to reuse methods/class from another maven project.
properties files are located into src/main/resource under folder-> ConfigFolder
When JAR is created the path of ConfigFolder changed and below line of code is failing System.getProperty("user.dir")+/src/test/resource/ConfigFolder/Configfilename.Properties
In maven project - *.Properties is being read by below line of code
new FileInputStream(System.getProperty("user.dir")+/src/test/resource/ConfigFolder/Configfilename.Properties")
When Project is converted into Jar using maven-jar-plugin, the hierarchy of Configfilename.Properties changes hence all my methods are failing.
Before converting JAR Folder Hierarchy
ProjectName(maven project)
|-src/main/java
|-src/test/java
|-src/test/resource
|-ConfigFolder
|-Configfilename.Properties
|-testSuites
|-testng.xml
After converting the into JAR
JARNAME-test.jar
|-ConfigFolder
|-Configfilename.Properties
|-testSuties
|-testng.xml
As you see after converting the jar the hierarchy got changed and new **FileInputStream(System.getProperty("user.dir")+/src/test/resource/ConfigFolder/Config.Properties") **returns null
requirement is to convert first maven project into JAR and use it into second maven project as first maven project contains n number of reusable methods/class project.

How to include a standalone jar that uses spring and beans as a dependency in maven project for jenkins plugin?

I want to include a standalone jar file (which uses spring), inside my java code to develop a jenkins plugin. When I add this as a dependency and I run the plugin ,I get errors like: Caused: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [com/XXX/YYY/jmsclient3/XXXclient-jms-config.xml]
It says cant find the class path resource [com/XXX/YYY/jmsclient3/XXXclient-jms-config.xml], because it doesnt exist.
But this file is clearly there in the jar. Its a bean file(I dont know much about it).

Springboot - Executing Fat Jar

I have a springboot application which creates a JAR artifact using maven build. I understand that we can execute this jar from command line by going into target folder and executing appropriate command but what I want to know that how can I export this jar to a different machine(Unix Box) and execute the jar?

How to create executable jar file from springboot - maven application?

When I tried to create a jar file using maven plugin in eclipse, I got thus error while trying to execute that jar:
Exception in thread "main" java.lang.IllegalStateException: Failed to
get nested archive for entry
BOOT-INF/lib/spring-boot-starter-actuator-2.0.3.RELEASE.jar
This seems to be a bug in 2017. Is there any solution for this now?
Your executable jar file doesn't contain above jar file.You should build jar with dependencies.
Right click project then click 'Run As'
Maven Build
And you should type 'package' in input area then run.
/path/your/project/target/ there is your .jar file with dependencies.

Extract all files from dependency

I'm trying to build a gradle task which extracts all files in a dependency, so that I can modify them using bytecode enhancement and repackage them to a custom jar.
How can I extract those files to my classes folder?
Interesting question. So lets split this up,
If you want the dependencies of a project as a File collection, Look at configurations for Gradle. For example, using the java plugin gives you the configurations, configurations.compile and configurations.runtime. See configurations
You can loop through collections using a each closure
You can see the contents of an archive using the zipTree method Example 1 Reference
You may also unzip an archive with the ant support within gradle, e.g.
ant.unzip(src: war.archivePath, dest: destFile)
You can finally build a custom jar using the Jar task type Jar Task

Resources