Spring MVC tutorial project does not build on IntelliJ - java

I am trying to build and run a Spring MVC beginner lesson project using IntelliJ. I imported the existing project from GitHub. But when I try to build the project I keep getting:
Error:(3, 38) java: package org.springframework.stereotype does not exist
Error:(4, 47) java: package org.springframework.web.bind.annotation does not exist
These external dependencies jars are under my Maven local repositories (C:\Users\sudi.m2)and I can see in IntelliJ under Maven->Repositories that repo location is indeed there. I also tried "Invalidate Cache and restart" but that does not help. My M2_HOME is set correctly to C:\apache-maven-3.2.2. If I try to run mvn install from command line, I get:
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 40.845 s
[INFO] Finished at: 2014-09-25T19:03:21+05:30
[INFO] Final Memory: 9M/93M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project basic-web-app: Error assembling WAR: webxml attribute is required (or preexisting WEB-INF/web.xml if executing in update mode) -> [Help 1]
Any suggestions are appreciated.

If the project doesn't have a web.xml file (IE: Entirely java config based). The build war plugin will fail unless you specify the "failOnMissingWebXml" attribute to false.

Delete you local .m2 repository and let it re-download all needed jars. Maybe, there were issues while downloading one of the dependencies.

Related

Spring Boot native:compile with multi module Maven build

I try to compile GraalVM Native Image for a Spring Boot 3.0 application with multiple Maven modules.
The module structure is like the following:
heroes-parent
|- heroes-backend
|- heroes-frontend
|- heroes-webapp
where each sub-directory is a module of the parent
pom.xml extract:
<modules>
<module>heroes-backend</module>
<module>heroes-frontend</module>
<module>heroes-webapp</module>
</modules>
When I try to build the app with (see Spring Boot docs):
mvn -Pnative native:compile
it errors with (because the parent has no classes):
[ERROR] Failed to execute goal org.graalvm.buildtools:native-maven-plugin:0.9.18:compile (default-cli) on project heroes-parent: Image classpath is empty. Check if your classpath configuration is correct. -> [Help 1]
So, I have tried to build the whole application first with mvn install and then only build the application heroes-webapp with native:compile
mvn install
cd heroes-webapp
mvn -Pnative native:compile
But this fails with the following error:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.047 s
[INFO] Finished at: 2022-12-12T16:26:20+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.0.0:process-aot (process-aot) on project heroes-webapp: Unable to compile generated source
[ERROR] cannot access heroes.WeblateProperties
[ERROR] bad class file: /home/koc/git/work/koc/angular-spring-heroes/heroes-webapp/target/classes/heroes/WeblateProperties.class
[ERROR] unable to access file: java.nio.file.NoSuchFileException: /home/koc/git/work/koc/angular-spring-heroes/heroes-webapp/target/classes/heroes/WeblateProperties.class
[ERROR] Please remove or make sure it appears in the correct subdirectory of the classpath. /home/koc/git/work/koc/angular-spring-heroes/heroes-webapp/target/spring-aot/main/sources/heroes/WeblateProperties__BeanDefinitions.java 15:25
[ERROR] cannot access heroes.MainController
[ERROR] bad class file: /home/koc/git/work/koc/angular-spring-heroes/heroes-webapp/target/classes/heroes/MainController.class
[ERROR] unable to access file: java.nio.file.NoSuchFileException: /home/koc/git/work/koc/angular-spring-heroes/heroes-webapp/target/classes/heroes/MainController.class
[ERROR] Please remove or make sure it appears in the correct subdirectory of the classpath. /home/koc/git/work/koc/angular-spring-heroes/heroes-webapp/target/spring-aot/main/sources/heroes/MainController__BeanDefinitions.java 15:25
[ERROR] cannot access heroes.HeroesApplication
[ERROR] bad class file: /home/koc/git/work/koc/angular-spring-heroes/heroes-webapp/target/classes/heroes/HeroesApplication.class
[ERROR] unable to access file: java.nio.file.NoSuchFileException: /home/koc/git/work/koc/angular-spring-heroes/heroes-webapp/target/classes/heroes/HeroesApplication.class
[ERROR] Please remove or make sure it appears in the correct subdirectory of the classpath. /home/koc/git/work/koc/angular-spring-heroes/heroes-webapp/target/spring-aot/main/sources/heroes/HeroesApplication__BeanDefinitions.java 18:25
You can find the source code for the whole application on GitHub.
Is there any way to build a native-image with a Maven multi-module Spring Boot 3 application?
I found the issue. Visual Studio Code was open and the project was loaded using Extension Pack for Java. This was deleting the classes while Maven was building them which resulted in the error above.

Project added in build path but eclipse showing project not exist

I have a project say A and I have another project B.
I am trying to use project B in project A and so I added project B in project A's build path specifically Classpath.
After adding the import, error got resolved from eclipse IDE but when I am doing mvn clean install there is a compilation error saying package com.examples does not exist.
I tried adding as external jars as well but still it is not working.
Project A is Spring boot project version 2.7.5.
Java version is 17.
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.568 s
[INFO] Finished at: 2022-10-23T14:48:00+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project proj: Compilation failure: Compilation failure:
[ERROR] /C:/Users/user/eclipse-workspace/proj/src/main/java/com/name/proj/Application.java:[6,30] package com.examples does not exist
Note: Both projects are running successfully independently.
Please help me to resolve this issue.

Maven Build failure in command prompt but getting build in eclipse

I am using mvn clean command from the command prompt and build is failing.
Downloading:
https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-
plugin/2.5/maven-clean-plugin-2.5.pom
[INFO] Reactor Summary:
[INFO] ABC ......................................... FAILURE [ 2.226 s]
[INFO] BUILD FAILURE
[INFO] Total time: 3.098 s
[INFO] Finished at: 2018-11-16T15:10:36+05:30
[INFO] Final Memory: 12M/153M
[ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of
its
dependencies could not be resolved: Failed to read artifact descriptor for
org.apache.maven.plugins:maven-clean-plugin:jar:2.5: Could not transfer
artifact
org.apache.maven.plugins:maven-clean-plugin:pom:2.5 from/to central
(https://repo.maven.apache.org/maven2): Received fatal alert:
protocol_version -
> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e
switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] For more information about the errors and possible solutions,
please
read the following articles:
[ERROR] [Help 1]
http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
But when I am using mvn clean command from inside of eclipse it is building successfully.
[INFO] ---------------------------------------------------------------------
---
Downloading:
http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-
plugin/2.4.1/maven-clean-plugin-2.4.1.pom
Downloaded:
http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-
plugin/2.4.1/maven-clean-plugin-2.4.1.pom (5 KB at 5.2 KB/sec)
-------------------------
[INFO] BUILD SUCCESS
[INFO] Total time: 4.387s
The difference i am able to see is that , in command prompt it is trying to download maven-clean-plugin-2.5 whereas from eclipse it is successfully downloading 2.4.1
But I need to run through 2.5 only .
Can anyone help me on this.
Thanks.
I don't know did you install maven globally. You can try to install maven globally. follow the steps.
Download maven from maven download link
Create or export M2_HOME="MAVEN ROOT LOCATION". Ex. : E:\SoftwareRepo\building tools\apache-maven-3.5.2
Create or export MAVEN bin folder location to PATH variable. For example: E:\SoftwareRepo\building tools\apache-maven-3.5.2\bin
Open terminal or cmd and run mvn --version to confirm maven is installed or not.
You can use this same as with Eclipse.
Then go to eclipse. and setup project.follow this steps
Import existing maven project or create a maven project
Goto project explorer and Right click on your pom.xml
then select Run As maven install.
and then what you want.
Hope it will serve your purpose. You can download a sample spring boot project .
Or you can run a maven project from terminal or cmd. Just goto project root folder and then run a maven task like maven clean install . Happy Coding :)

How do I get Maven Site Descriptors to deploy to Artifactory?

I'm trying to generate a site for project that has a parent project and getting the following error.
[INFO] Parent project loaded from repository: com.mycompany:java-parent:pom:2.0.8
[INFO] Parent project loaded from repository: com.mycompany:parent:pom:2.0.8
Downloading: http://mycompany.com:8083/artifactory/ecommerce-repos/com/mycompany/parent/java-parent/2.0.8/java-parent-2.0.8-site_en.xml
[INFO] Unable to find resource 'com.mycompany:java-parent:xml:site_en:2.0.8' in repository eecomdev1-eecom (http://mycompany.com:8083/artifactory/ecommerce-repos)
Downloading: http://repo1.maven.org/maven2/com/mycompany/parent/java-parent/2.0.8/java-parent-2.0.8-site_en.xml
[WARNING] Unable to get resource 'com.mycompany:java-parent:xml:site_en:2.0.8' from repository central (http://repo1.maven.org/maven2): Error transferring file: Connection refused
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] SiteToolException: The site descriptor cannot be resolved from the repository: IOException: Unable to locate site descriptor: Permission denied
I'm unsurprised that it can't find it at repo1. A check of our company repository showed that the site_en file has not been deployed to our artifactory.
The site does generate from the machine where we do most of our builds. It turns out that because it built the actual releases for parent and java-parent it has the site_en.xml file in its local repository (the one on the local disk).
I figure to get going I need 1 of 2 possible solutions:
A way to tell the child project to stop trying to find the parent projects site.xml.
A way to deploy the site.xml files to artifactory.
My attempts at finding either solution have failed. The only way I can get the site xml files into the local artifactory is by running a full mvn release:prepare release:perform. I can't figure out how to make it deploy these files to artifactory or how to generate these files without actually doing a release.
Any ideas?
did you try instructions from http://maven.apache.org/plugins/maven-site-plugin/maven-3.html#Site_descriptor_attachment?
with this configuration in place, you should be able to simply mvn deploy
I think that it is related to this open bug https://issues.apache.org/jira/browse/MSITE-639

Problems after Maven installation - mvn install tries to download unreachable files

After installing maven (mvn -v works fine), I tried to do mvn install in a directory having a good pom.xml at the root of a Maven project that I know works.
I get the output shown at the bottom which basically states that it tried to download a file from an online maven repository and failed. The file appears to be maven-oriented and I don't think it's related to my project.
In addition, if I run mvn install in a directory without a pom.xml, which should just fail as I understand it, I get the same problems. I'm guessing my Maven just hasn't been fully set up yet and its configuring itself maybe?
Can anyone tell me why it wants these files, and why it might be failing?
I seem to have access to the URL in chrome and the file being targeted is there, so even if it does need it, I'm baffled about why the download is failing.
C:\>mvn install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO] task-segment: [install]
[INFO] ------------------------------------------------------------------------
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.3/maven-resources-plugin-2.3.pom
[WARNING] Unable to get resource 'org.apache.maven.plugins:maven-resources-plugin:pom:2.3' from repository central (http://repo1.maven.org/maven2): Error transferring file: Connection timed out: conne
ct
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.3/maven-resources-plugin-2.3.pom
[WARNING] Unable to get resource 'org.apache.maven.plugins:maven-resources-plugin:pom:2.3' from repository central (http://repo1.maven.org/maven2): Error transferring file: Connection timed out: conne
ct
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).
Project ID: org.apache.maven.plugins:maven-resources-plugin
Reason: POM 'org.apache.maven.plugins:maven-resources-plugin' not found in repository: Unable to download the artifact from any repository
org.apache.maven.plugins:maven-resources-plugin:pom:2.3
from the specified remote repositories:
central (http://repo1.maven.org/maven2)
for project org.apache.maven.plugins:maven-resources-plugin
Your gateway is blocking maven from downloading the dependencies.
Try and check whether you are able to download this pom file manually.
http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.3/maven-resources-plugin-2.3.pom
if you are open the above URL from your browser, then check your firewall settings(Sometimes firewall settings also block maven from downloading the dependencies, especially if you are in an enterprise environment).
if that is the case, you need to use a proxy to bypass your gateway and download the dependencies
OR
Download the plugins manually from maven central or nexus repository and install it using maven install command in your local .m2 directory.
maven install -DartifactId="your dependency" -DgroupId="groupID of the
dependency" -DFile="your file location"
As you mentioned in the comments that you are able to open the site from chrome, you can install the dependency using the above command.
Unable to download the artifact from any repository maven:
Check for proxy :if you have some customized jar file related to your company project ,it needs your firewall and if you are using any proxy in setting.xml file then block it to get it downloaded.

Categories