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

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).

Related

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

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.

Tomcat not starting after changing packaging from jar to war

Firstly, after changing the packaging from jar to war for spring boot application, I am not able to do maven build. Getting below error:
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.goel.GameApplication]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/application.properties]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:189)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331)
The above error comes when maven tries to run app tests. So I commented out the test and ran maven build and I was able to get a war file.
But after deploying the same war file in tomcat(aws), I am getting the same error.
I have followed the 3 step approach properly.Ref: https://www.javadream.in/convert-jar-to-war-in-spring-boot/
I have checked that the build-path does not exclude resource or application.properties
I have tried moving from spring IDE to Eclipse IDE.
I have opened the war file and have verified that the application.properties file is present under WEB-INF/classes/application.properties.
I have read and tried many other things but nothing helped. Any pointers will be helpful. Thanks in advance.
Please do let me know if more info is required,
Java Version: 1.8 ,
Maven Version: 3.6.3 ,
spring-boot-starter-parent: 2.5.4
Exploded war file
Screenshot for SSGApplication

Dependent JAR: cannot find properties file

I have a library using Spring and loading its own properties file
#Configuration
#PropertySource("classpath:connectors.properties")
When using this JAR as a Maven dependency, and putting that class under scanning, I get the following error:
java.io.FileNotFoundException: class path resource [classpath:connectors.properties] cannot be opened because it does not exist
What is the proper way in this case?
Thanks
Actually as pointed out by #Barath, the file had not been packaged in the dependent JAR, as it was present in src/test/resources and not src/main/resources

Spring Boot 1.4.3 Embedded Tomcat NoSuchMethodError StringManager.getManager

I have update my project to use Spring BOOT 1.4.3. The code compiles and runs without issues from Eclipse Neon 1.
But when I run from command line
mvn clean install -DskipTests
java -jar myweb\target\my-web-1.0-SNAPSHOT.jar
I get runtime error and tomcat is not starting
Caused by: java.lang.NoSuchMethodError: org.apache.tomcat.util.res.StringManager.getManager(Ljava/lang/Class;)Lorg/apache/tomcat/util/res/StringManager;
at org.apache.catalina.util.LifecycleBase.<clinit>(LifecycleBase.java:43) ~[tomcat-embed-core-8.5.6.jar!/:8.5.6]
Please can you tell why? How to find which tomcat is used at runtime, as my understand is that 8.5.6 is having compile scope(?)
Please help. If the suggestion is to use tomcat.version in properties of POM file or add tomcat-juli dependency, then please help me understand why it is required?
Impatient stackoverflow'ers dont just flog new comers only because you can do. You can easily ask if you want my POM, but I used just spring-boot-starter-web thats it.
For this kind of problem, it's often due to multiple jar having the same class inside your classpath, so :
Find where this class / method could come from, by opening the type popup (CTRL + SHIFT + T in Eclipse). It will display you every jar in your classpath that contains the class.
Open the class in each jar to see which one contains your method and which one don't.
Display the dependency hierarchy of your project with mvn dependency:tree
If the 2 jars are in your classpath, you might exclude the one that don't contain the method.

mvn jboss:deploy fails with NoClassDefFoundError

When deploying an EJB project to JBoss using JBoss Maven Plugin, I get a NoClassDefFoundError on my JBoss' console about a class that is in one of the dependencies of this EJB project.
This dependency is declared with a Compile scope. Is there another scope that I should use so that my dependencies are also deployed to JBoss? Or how should I solve this?
The error looks like this:
DEPLOYMENTS IN ERROR:
Deployment "vfszip:/Users/hordine/projects/SoftBudget/soft-budget-ejb/target/soft-budget-ejb.jar/" is in error due to the following reason(s): java.lang.NoClassDefFoundError: br/com/pedra/j2eepatterns/facade/IEntityService
I understand that you have packaged the EJB as a jar file. This means there is no any provided dependency as same as a stand-alone jar.
AFAIU, there may be 3 possible ways as the following: -
Package them as an ear and put those dependencies inside the ear/lib. Please see Maven EAR Plugin for further information.
Package them as an war and put those dependencies inside the WEB-INF/lib. Please see Maven WAR Plugin for further information.
Package them as an jar and put those dependencies inside the classpath or application server lib. Please refer to your application server document.
EDITED:
If you are using the JavaEE 6, then it is possible to package the EJB as a war file. The The Java EE 6 Tutorial: Packaging Enterprise Beans in WAR Modules told us as
Enterprise beans often provide the business logic of a web application. In these cases, packaging the enterprise bean within the web application’s WAR module simplifies deployment and application organization. Enterprise beans may be packaged within a WAR module as Java programming language class files or within a JAR file that is bundled within the WAR module.
To include enterprise bean class files in a WAR module, the class files should be in the WEB-INF/classes directory.
To include a JAR file that contains enterprise beans in a WAR module, add the JAR to the WEB-INF/lib directory of the WAR module.
WAR modules that contain enterprise beans do not require an ejb-jar.xml deployment descriptor. If the application uses ejb-jar.xml, it must be located in the WAR module’s WEB-INF directory.
I hope this may help.

Resources