Classpath Error : Unable to fetch Properties from another Project - spring

I have a SpngBoot Proj where it uses Another Spring Boot Project as Dependency in pom.xml, When i run the first Proj it's giving "Could not find Properties(of 2nd Proj), Classpath resource <com/xyz/abc/pqr.properties> (Prop of 2nd proj) can't be opend cause it doesn't exist". Any help would be appreciated!

Related

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

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.

STS maven project not showing all files

STS screen image
I have created new maven project from start.spring.io
But after importing .jar file in STS tool its not showing src/main/java ,src/main/resources etc files
what to do any idea?
Your POM.xml is indicating an error. Have look at your POM.xml and fix the error, maybe Maven is unable to find a dependency or your POM.xml is broken (-> bad syntax?). If Maven can properly find all dependencies and accepts your POM.xml , STS will then show the correct Maven project structure.

Gradle: Can't resolve a variable that has to be included in external dependency

This question follows this post: Gradle: Where are external dependencies stored?.
I want to use MongoDB driver for Java, so I added the following line:
compile 'org.mongodb:mongodb-driver:3.4.0'
to build.gradle file. After finishing the build successfully, I found the jar file of the dependency in ~/.gradle/caches/modules-2/files-2.1/org.mongodb.
I also added the path ~/.gradle to external libraries.
However, when I write the statement
import com.mongodb.MongoClient;
inside my project, I get an error:
"Can't resolve symbol 'mongodb'".
Do you know how to resolve this issue?
Now IJ searches in .gradle for classfiles. Of course mongodb is not found in there. As I said in the comment of the other issue, if you change the dependencies in your Gradle file and did not enable auto-import when you imported the Gradle project into IJ, its library configuration will not automatically update. Either tell IJ manually to refresh the library configuration from the Gradle file or activate auto-import so that it automatically sees when you change the Gradle file and automatically updates the library configuration.
Make sure you opened the project as Gradle project
When you add dependency, press on the sync dependencies button

Publishing a Spring Gradle Project as jar

I created a gradle project having common code among all the projects in the same workspace. For this,
I set this new project in class path of all other projects. So it is available at compilation time.
I mentioned package structure of new project in application-context (spring configuration) of all projects. So that the component of new project can be autowired.
In build.gradle of every project, I have addedn an extra entry under dependencies task i.e. compile project(':newproject')
Everything is running fine. Only I need to figure out gradle task to generate jar of new project.
Is it the correct way? Or should I
build jar of new project,
define it as dependency in build.gradle of other projects,
copy it libs folder of other project at the time of deployment.
In 2nd approach, I have no idea how Spring'll autowire the bean of newproject.
Adding the dependencies manual via a build jar file would be strange. I would stay with the "correct" dependencies and try to figure out a way to build the jar of "new project".

Resources