Spring Boot with spring-boot-starter-web fails to compile in maven - spring

I am using jdk1.7 and spring boot 1.4.2.Release.I created a brand new Spring boot project from start.spring.io. It compiled fine. I tried to add the below dependency for exposing a REST web service.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
I get the below error:
[ERROR] Failed to execute goal on project demo: Could not resolve
dependencies for project com.example:demo:jar:0.0.1-SNAPSHOT: Failed to
collect dependencies at org.springframework.boot:spring-boot-starter-
web:jar:1.4.2.RELEASE -> org.hibernate:hibernate-validator:jar:5.2.4.Final:
Failed to read artifact descriptor for org.hibernate:hibernate-
validator:jar:5.2.4.Final: Could not transfer artifact
org.jboss.shrinkwrap:shrinkwrap-bom:pom:1.2.2 from/to spring-ext
(http://repo.spring.io/ext-release-local/): repo.spring.io: Unknown host
repo.spring.io -> [Help 1]
It takes the http://repo.spring.io/ext-release-local link which does not have jboss related files.
Please let me know if I am doing something wrong.

Your pom should look like this
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
after that you need to run it with command mvn spring-boot:run from the project directory
I hope this time it will defenetly work only need to copy and pase this pom content to your pom file
To build spring boot application from scratch you can follow the link

In my case, just adding the repository configuration to the pom.xml didn't work. I had to add the following code into /maven-installation-dir/conf/settings.xml file.
<mirror>
<id>central-proxy</id>
<name>central-proxy</name>
<url>http://corporate-intranet/repo/url</url>
<mirrorOf>central</mirrorOf></mirror>
I hope it helps someone.

Related

Why does pom.xml file give an unknown error

I,m trying to learn spring boot and install spring boot to eclipse IDE. When I create my first project it shows an error in first line of pom.xml. It shows as unknown error.
I tried many solutions from stackoverflow. But none of them work for me.
Maven pom.xml error in eclipse
When maven says "resolution will not be reattempted until the update interval of MyRepo has elapsed", where is that interval specified?
My pom.xml as below.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Can anyone help me for resolve this.
I got the same problem 2 weeks ago. Then, I fixed it with adding a line as below
<properties>
<!-- ... -->
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
</properties>
And it seems the error was fixed in Eclipse already.
Just update your Eclipse or STS4. You may see m2e connector is involved in the update list.

Error: Failed to execute goal on projectorg.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile

I tried configuring spring framework in eclipse. And try building a sample. It is giving me the following error.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project springBootHelloWorld: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[ERROR] Failed to execute goal on project springBootHelloWorld: Could
not resolve dependencies for project
com.javaInUse:springBootHelloWorld:jar:0.0.1-SNAPSHOT: The following
artifacts could not be resolved:
org.springframework:spring-core:jar:5.0.10.RELEASE,
org.xmlunit:xmlunit-core:jar:2.5.1: Could not transfer artifact
org.springframework:spring-core:jar:5.0.10.RELEASE from/to central
(https://repo.maven.apache.org/maven2):
C:\Users\jkalansrayan.m2\repository\org\springframework\spring-core\5.0.10.RELEASE\aether-f4279e83-b0c7-471b-8dca-f684b2238c2d-spring-core-5.0.10.RELEASE.jar-in-progress
(The system cannot find the file specified) -> [Help 1]
POM FILE
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.javaInUse</groupId>
<artifactId>springBootHelloWorld</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>springBootHelloWorld</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Check internet connectivity because it may be proxy issue.
Remove local maven .m2 reposiotory folder and do mvn clean install again will resolve the issue.
If above solutions don't work then attach the pom.xml file in the question.

Spring Boot Maven project build error with STS

I am getting the below error message while creating a new spring starter project in Spring STS
project build error: Non-resolvable parent POM for com.test:security:1.3.8-SNAPSHOT: Failure to transfer
org.springframework.boot:spring-boot-starter-parent:pom:1.3.8.RELEASE from https://repo.maven.apache.org/maven2 was
cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates
are forced. Original error: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:1.3.8.RELEASE
from/to central (https://repo.maven.apache.org/maven2): connect timed out and 'parent.relativePath' points at no local POM
POM.XML:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>security</artifactId>
<version>1.3.8-SNAPSHOT</version>
<packaging>jar</packaging>
<name>security</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.8.RELEASE</version>
<relativePath />
<!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
For every spring starter project I am getting the above error message.
you should update your Spring boot parent dependency to to the latest realease 1.5.3:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
</dependency>
Are you using Maven 2 or Maven 3.x?
According to the documentation, Spring Boot is compatible with Apache Maven 3.2 or above (https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#getting-started-maven-installation)

Non-resolvable parent POM in Maven Project made with http://start.spring.io/

I've created a Maven Project using Spring Initializr, but when I try to build it I get the following error:
[ERROR] The project com.example:demo:0.0.1-SNAPSHOT (/home/alessandro/Work/workspaces/demo/pom.xml) has 1 error
[ERROR] Non-resolvable parent POM for com.example:demo:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:1.4.2.RELEASE from/to repo (http://artifactory.dev.*****.it/artifactory/repo): Failed to transfer http://artifactory.dev.*****.it/artifactory/repo/org/springframework/boot/spring-boot-starter-parent/1.4.2.RELEASE/spring-boot-starter-parent-1.4.2.RELEASE.pom. Error code 504, Gateway Time-out and 'parent.relativePath' points at no local POM # line 14, column 10 -> [Help 2]
the auto-generated pom.xml is the following:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
I tried to specify a relative path inside the parent tag (like '../pom.xml') without success, can anyone help me please?
Thanks
Nothing to do with start.spring.io.
You most probably have a custom ~/.m2/settings.xml where everything (or Maven Central) is proxied to http://artifactory.dev.*****.it/artifactory/repo/
Failed to transfer http://artifactory.dev.*****.it/artifactory/repo/org/springframework/boot/spring-boot-starter-parent/1.4.2.RELEASE/spring-boot-starter-parent-1.4.2.RELEASE.pom.
If that artifactory server is supposed to fetch outside, maybe there's a network glitch or something. Regardless, please ask the admin of that server for help.

POM error: Failure to find org.springframework.boot

I have been trying to setup a spring boot project but am getting an error. I researched and tried various options but no luck so far. Any help would be appreciated.
Project build error: Non-resolvable parent POM: Failure to find org.springframework.boot:spring-boot-starter-parent:pom:1.1.3.RELEASE in http://repo.maven.apache.org/
maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced and
'parent.relativePath' points at no local POM
POM.XML (error in parent tag)
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.programmingfree</groupId>
<artifactId>spring-data-rest-angular</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Spring Data Rest + AngularJS</name>
<description>This project uses Spring Data Rest and AngularJS to perform CRUD operations against MySql Database.</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>com.programmingfree.springservice.Application</start-class>
<java.version>1.7</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
There might have been some intermittent Internet issue or something. I was facing the same problem yesterday. Updating the the project (On STS or Eclipse, right click on the project and Maven -> Update project -> tick everything except Offline) after sometime fixed it.
I got a similar exception while maven-build process.
If you are using a proxy network - update settings.xml in your maven folder
../apache-maven-3.2.3\conf/settings.xml
settings.xml content
<proxies>
<proxy>
<id>...</id>
<active>true</active>
<protocol>http</protocol>
<username>....</username>
<password>....</password>
<host>....</host>
<port>....</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
</proxies>
project(right click) -> Maven -> Update project -> tick everything (except OfflinI)
I got the issue resolved.
Check Settings.xml file mapping in Eclipse Window->Project->Maven->User Settings, It should be default xml provided from Maven config folder. You might have configured your own xml file which suites for you project needs.
I tried few things
1. set up the settings.xml file
2. Update maven project option for eclipse didin't solved my issue
3. Run the following command manually , my issue got resolved
mvn dependency:purge-local-repository
Change the version of springboot to the next version or previous version and do update the pom file. It worked for me. I had issue with spring boot 2.1.5 so I changed it to 2.1.4 in the pom file and updated it. It worked.
Delete the repository in .m2 folder, perform Maven install and update the project , it worked for me.
Attaching pom.xml file here.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.8</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.springbootproject</groupId>
<artifactId>SpringBootRestServices</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SpringBootRestServices</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
This happened because the STS is not able to find the Parent POM location. You can go to Command Prompt and exectute mvn -x to get location of your Global and Local Settings.xml file.Go to Window-> Preferences-> Maven, and then set the locations for both Gloabal and User level with the above command locations. Then right click on the project and Goto Maven-> UpdateProject. This will solve the problem
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.programmingfree</groupId>
<artifactId>spring-data-rest-angular</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Spring Data Rest + AngularJS</name>
<description>This project uses Spring Data Rest and AngularJS to perform CRUD operations against MySql Database.</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>com.programmingfree.springservice.Application</start-class>
<java.version>1.7</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
I am facing this issue as i am writing this answer. Well seems my office internet settings has restricted downloading content using tools like eclipse. I have faced issues with multiple tools like eclipse, youtube-dl. When I use my mobile internet for my laptop it works fine. That means it has got to do something with the internet settings.

Resources