Spring Boot 1.5.2 Starter Project - spring

I am creating a simple spring boot project by going to http://start.spring.io and selecting web and actuator as dependencies. My spring boot version is 1.5.2.RELEASE. The project gets downloaded to my local machine. Then I unzip the project and import as a maven project to my workspace. I use spring STS IDE (I don't think it matters. But i just wanted to mention this). I do see errors in my project. Apparently it is a build path problem and it is complaining about spring-context-4.3.7.RELEASE.jar. I do see this jar in my maven repository and in java build path though. Anybody knows what this problem is? If I just create a spring boot application with version 1.3.8, it works without any issues and I don't see any build path problem. Am I doing something wrong or could this be a spring packaging issue?

I sometimes get similar errors when my local Maven repository is corrupted.
To fix it, close Spring Tool Suite, then go to <HOME>/.m2/ and delete the repository/ folder or just the folder you think is the culprit, like repository/org/springframework/spring-context/4.3.7.RELEASE/.
Notice that this will result in the need to download again the deleted artifacts.
After that, in you Spring Tool Suite, right-click on your project > "Maven" > "Update project..." > Make sure the right project is selected > "OK".
EDIT
There is a way in Spring Tool Suite (and eclipse I suppose) to know which artifact is corrupted: in the "Problems" view. To show it:
Windows -> Show View -> Problems
And there should be an error entry about a corrupted artifact, like the following:
Archive for required library: 'C:/Users/{username}/.m2/repository/path/to/file.jar' in project 'my-project' cannot be read or is not a valid ZIP file
The project cannot be built until build path errors are resolved

Thanks for taking time out to post this reply. I tried this prior to making my initial post. Sorry, I didn’t list down everything I tried only because I had tried everything I could think of – for hours and hours. What worked for me is changing the version to 1.5.1.RELEASE from 1.5.2.RELEASE in my pom file; and then in Spring Tool Suite, right-clicking on the project and doing a "Maven" -> "Update project"
So now I have the following in my pom file.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
I believe it has to do something with the way that spring boot team package their artifacts. This must be a bug.

Related

Intellij MavenWrapperDownloader.java: Can not resolve symbol error

Setup:
Intellij IDEA community edition 2020.2
Spring Bott starter parent: 2.3.5
Java 11
WRAPPER_VERSION: 0.5.6
mvn 2
Hi,
I googled a lot e.g. here but I just can't fix it.
I created a new mvn spring project with Intellij. When I commit the project I get errors detected by code analyses in class: MavenWrapperDownloader.java.
e.g. It reports:
Cannot resolve symbol String
I tried:
invalidate caches and restart
delete .idea folder and reimport
checked sdk setup
mvn reimport
mvn clean and then rebuild (while the build is always successful)
I'm pretty new to maven. I guess the scope of the mvn package might be wrong because the build process works as expected.
UPDATE:
I reinstallt my openjdk11. No success. Then I found out that my .mvn/wrapper dir is not set as source root. I know that was never the case in my other projects. As a trial I've set my .mvn folder as source root and now the MavenWrapperDownloader.java file is recognized as a java class and the compiler interprets the symbols. But now there is another error. It says I have to define a package name for that class because the class does not have one per default. It is pretty strange to me. I also tried to use another spring boot starter version but nothing changed
When I execute Analyze->inspect code I get the following:
I had the same problem and File -> Invalidate Caches/Restart fixed it - at least for now.
IntelliJ Ultimate 2020.3
Spring Boot Starter Parent 2.4.2
Java 15
Maven 4.0.0
Maven Wrapper 0.5.6
The easiest solution is to generate your project again with Spring Starter.
After you set up everything you need at pom file -> Generate -> Download it.
Open with your IDE and copy-paste all code sources which you have already written.

can't find my maven artifacts

I'm working in eclipse and I have a problem that I can't import my personal java libraries.
I created the libraries and 'installed' them into my local maven repo (using mvn install). This created a subdirectory related to the 'version' name that was in the POM file from when I ran the command. Which seemed fine.
So in this directory there where the usual jar files and other stuff.
When I released this file I manually changed the name of the version in the POM. going from 0.0.1-SNAPSHOT to 0.0.1-RELEASE
This seems to have worked as I would have expected.
However I can't seem to find import the new release jar.
Using the maven repositories browser in eclipse I can see that the new artifact is in the 'local' repository.
I try to add the dependency in the following methods:
Select the main project -> Maven -> add dependency.
This adds the dependency details into the pom but with a type value detail of <type>pom.lastUpdated</type>
Select the project pom.xml file -> Maven -> add dependency.
This time the artifact for the 0.0.1-RELEASE is greyed out I can select it, but I guess nothing is actually happening.
The original 0.0.1-SNAPSHOT it selectable, and if I use this I do not have a <type> detail in the pom.
I don't understand why there is a difference in the RELEASE and SNAPSHOT artifacts, as they have both been generated in the same way, and clearly they are both visible in the browser, the contents of the directory on disk are the same. The file names and contents are identical with the exception of the word RELEASE or SNAPSHOT.
I know that I can simply add in the RELEASE jar to my build path, but this seems to be a ridiculous thing to have to do if I intend to use maven (or do I need to do this).
I don't want to use an external repo for storing my artifacts, and I'm not too keen to go to the trouble of installing nexus (or similar) on my local machine (just because I've had trouble with it in the past).
What am I missing so as I can get my maven project to see my local repository and all its artifacts.
Thanks in advance.
David
ps I've already tried things such as mvn dependency:purge-local-repository which definitely pulled in / updated all the local jar dependencies.
So I've managed to work around my problem.
As such this solution is ridiculous, and breaks all the purpose of maven.
So I found (from running maven from the cli) that there was an error in the parent of the project I was attempting to use.
The parent was missing a direct link to the scm plugin (version error).
Once I solved this problem, I then returned to the sub project, and got a lot of errors from missing stuff from the parent.
Essentially it was not 'seeing' all the log4j dependencies.
The solution (well non-solution really).
Add all the log4j dependencies to the sub project.
Edit in SCM and surefire test plugins (as it also started to fail the test code due to missing junit).
So this is great.
I have to define all my dependencies on log4j and in my sub / child project's pom.xml file.
I also need to define them all in my parent's pom.
As it then still refused to run tests in my new project (that used the above as a dependency), and refused to find log4j also. I then decided to add all of these as dependencies for my current project.
Great.
I thought the whole point of maven was I could define my dependency on log4j in my my logging library that I use (which is the dependency), and then it would 'automagically' pull in all the required from this dependency.
Clearly not.
As stated at the start. This is NOT AN ANSWER it is a crazy work around.
My logging library that I use should be able to define its own requirement on a specific log4j version (such as moving from log4j to log4j2), and then when I include this as a maven dependency any change to the required dependency should be seen automatically.
But No : I have to import the dependency on log4j in my other projects also. So now if I had updated my logging library from log4j to log4j2 I would need to go to all my project that use this library and update their pom's to ensure that I have the correct version of log4j.
Seems the whole point of maven has just been lost!
Can someone please tell me where I am going wrong!
David.

What is the correct Eclipse setup for JHipster?

I am getting this error from the first attempt to get a jhipster project compiled in STS Eclipse.
The type org.springframework.core.NestedRuntimeException cannot be resolved. It is indirectly referenced from required .class files CustomPersistentRememberMeServices.java /us-modeldrivers-jhipsterTest003/src/main/java/us/modeldrivers/jhipsterTest003/security line 1 Java Problem
My process so far :
Install jhipster and run a project build
Create a Spring project in STS Eclipse
Update the pom to that generated by jhipster
Copy the jhipster code into the appropriate package in the eclipse project
Get "tools.jar not found error, so force eclipse to use JDK, not JRE
Get "javax.servlet.http.HttpServletResponse cannot be resolved" error, so add Tomcat runtime libary to the build path
Get the NestedRuntimeException not found error, fail to find any answers, realize must be doing something fundamentally wrong.
Any help gratefully received.
EDIT 2014-03-17
I installed fresh versions of STS, including 32 bit and older versions - same result - missing jar files.
I can get rid of missing javax.servlet.http.HttpServletResponse by adding
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_2.5_spec</artifactId>
<version>1.2</version>
</dependency>
I can get rid of missing javax.servlet.http.HttpServletResponse by adding
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
But jhipster cant expect you to add core spring to the pom to work.
Something must be wrong outside STS?
I have had the problem before that Maven tries to download the required jar files to Users\IBP.m2\repository\org\springframework\spring-instrument\3.0.5.RELEASE (for example). If this fails then it doesnt try again. So you find the thing that failed and delete its directory - that forces a re-download. But in this case the things that said to be missing are in .m2 from other projects.
Anyway, that is a total guess, and I am totally stuck.
I did the following steps and it works
Install the version 3.4.0 of sts
Generate a new project using yo jhipster command
Import the generated project in sts
Run the Application.java as application
Everything works.
This was caused by a corrupt Maven repository. I cleared out the maven cache and it worked fine. Thanks to the support guys of IntelliJ.
you can install sts in eclipse and import the project as existing maven project and then exclude the node_modes and bower components from project properties.
Your answer above is correct... the primary problem is more than likely that you're doing one of two things:
Copy/pasting code into STS rather than doing an import.
Trying to run the application by executing "Run on Server", rather than "Run as Spring Boot".
In the "Run As" context menu you should run "Maven clean" then "Maven install". Then you can start the application by "Run As/Java Application" on the Application class.

Cant get Spring SAML2 working

I can't seem to get saml2 working. Here is what I have done.
I downloaded the sample application from here: https://github.com/spring-projects/spring-security-saml, this was a link from their documentation: http://docs.spring.io/spring-security-saml/docs/1.0.x/reference/html/chapter-quick-start.html
1) converted the sample application 'saml2-sample' into an eclispe project: mvn eclipse:eclipse
2) built the project: mvn package
3) added the 'Dynamic Web Module` facet to the project:
Right Click on project > Properties > Project Facets
4) Run the application on the STS Server:
Right Click on project > Run As > Run on Server
Server starts up and everything looks ok in the console except the url loads with HTTP Status 404 - /spring-security-saml2-sample/ at the URL http://localhost:8080/spring-security-saml2-sample/
Please, follow these steps:
Download the project from Github as archive.
Unzip the archive.
By STS/Eclipse: File > Import > Existing Maven Projects and select as root dir {your_download_folder}/spring-security-saml-master/sample folder.
Now, you may see these errors:
Fix the pom.xml as shown in this gist.
In the end, you may also fix the MetadataController class (note that some methods have changed between versions).
The easiest way is to remove that class, otherwise you should fix it manually.
Finally, run the project as webapp.
That's all!
Annotation-based configuration
If you would like to use an annotation-based configuration, you could see this one: spring-boot-security-saml-sample.
The try to change the Spring Framework dependency to latest version's like 3.2.13 or 4.0.9. I'm able to run the application successfully with both of these dependencies. Also when you're updating spring dependencies, please make sure to change xsd version to what you're using spring version "securityContext.xml" and "saml-servlet.xml".
Fyi - I've use following versions in a pom.xml file
<properties>
<junit.version>4.12</junit.version>
<jsp-api-version>2.0</jsp-api-version>
<spring.version>4.0.9.RELEASE</spring.version>
<spring.security.version>3.2.5.RELEASE</spring.security.version>
<spring-security-saml2-core-version>1.0.0.RELEASE</spring-security-saml2-core-version>
<slf4j-log4j12-version>1.7.10</slf4j-log4j12-version>
<jstl.version>1.2</jstl.version>
</properties>

Java Maven Project appears in another project as directory not a jar

So, I created a Spring Maven Project, a Dao Project, which works great. All the code is in the correct place, all the unit tests run, and I can do a mvn clean install. I can see in the target directory that there is a build jar, and everything in it looks fine. I can also confirm that when I check my local .m2/repository, the latest jar I just built is in there.
Here is a small segment of that pom.xml:
<modelVersion>4.0.0</modelVersion>
<groupId>com.tom.myproject</groupId>
<artifactId>myproject-dao</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>My Project DAO</name>
Now, I am creating a new Spring Maven Web-Project for my UI, and this pom.xml starts out like:
<modelVersion>4.0.0</modelVersion>
<version>0.0.1-SNAPSHOT</version>
<groupId>com.tom.myproject</groupId>
<artifactId>myproject-ws</artifactId>
<name>My Web Project</name>
<packaging>war</packaging>
Also in this pom.xml file, one of the first dependencies I have is:
<!-- My DAO ProjectDependencies -->
<dependency>
<groupId>com.tom.myproject</groupId>
<artifactId>myproject-dao</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
I can see in eclipse that when I try to access the classes from this dao jar, that seems to work fine. When I compile the code here, that all works fine. And when I do a "mvn clean install" to build this war, I can see the target directory, and all the needed classes and jars come in, obviously there are hibernate, logging, and spring classes that are there in the WEB-INF/lib directory.
Now this is he part where the question comes in ... Why does the myproject-dao show up under WEB-INF/lib as WEB-INF/lib/myproject-dao-0.0.1-SNAPSHOT.jar but appears as a directory, and not a jar?
Certainly when I pull in other jars, they are just .jar files and not directories.
I should add, when you look in the Eclipse project under maven dependencies, the icon for all the other jars show them as files. The icon for my myproject-dao.jar uses the icon for a folder/directory, so clearly a directory named "myproject-dao.jar" is being created and not a file with zipped up contents into a jar file.
When I build the war file, and deploy the war, the app says it cannot find any of the classes in the myproject-dao.jar directory. I have to delete the FOLDER "myproject-dao.jar" from the WEB-INF/lib directory and manually copy over the FILE "myproject-dao.jar". I can then clearly see the icon that means this really is a file.
This is probably a simple fix, so if you can help me out, that would be great.
ANSWER:
I wasn't using the maven-assembly-plugin. But, I did find out what the problem is.
Both my DAO project and the WEB project are in the same workspace, and the DAO project was open, as a result, the maven dependency shown in Eclipse was a folder icon, and not the jar icon. When I closed the DAO project and looked back at the maven dependencies on the WEB project pom.xml file ... NOW it shows the icon as a jar and not a folder.
So, all I have to do build my dao.jar file with maven, and when it is successful, it is done.
Then I have to CLOSE the project within Eclipse.
In my web project pom.xml file, the icon will now show this as a jar file, and when it builds, it will pull in the jars.
I imagine this is a benefit if one is working on several prior project, you really do have the chance to look at what is in the jar file while the war is running.
In my case, I know my dao.jar is working, so I can build it, and close the project, and then make use of that jar anywhere I need it.
I wasn't using the maven-assembly-plugin. But, I did find out what the problem is.
Both my DAO project and the WEB project are in the same workspace, and the DAO project was open, as a result, the maven dependency shown in Eclipse was a folder icon, and not the jar icon. When I closed the DAO project and looked back at the maven dependencies on the WEB project pom.xml file ... NOW it shows the icon as a jar and not a folder.
So, all I have to do build my dao.jar file with maven, and when it is successful, it is done.
Then I have to CLOSE the project within Eclipse.
In my web project pom.xml file, the icon will now show this as a jar file, and when it builds, it will pull in the jars.
I imagine this is a benefit if one is working on several prior project, you really do have the chance to look at what is in the jar file while the war is running.
In my case, I know my dao.jar is working, so I can build it, and close the project, and then make use of that jar anywhere I need it.
Thanks for the help!

Resources