Spring-Boot application does not build properly - java

my problem is when I trying to run my spring-boot project via STS or simple JavaApplication the changes after the last maven build are not built.
I'm tried several methods but, if I don't use maven build the project changes are not rebuilt.
Do you have any tips, what's wrong?
In the Project menu Build Automatically is selected. And the main method is annotated with #SpringBootApplication
(The hot-swap is not working too for me.)

I think . do clean first then right click project Maven-> update Maven. do clean again. plz

I found the solution. In the .project file for my project I simply added a javabuilder build command. After that STS works perfectly and rebuilds the project before start. I think this problem occurs because I created a maven project, instead of creating a java project and convert it to a maven project.

If your project is gradle then go to Project right click and go to >gradle >Refresh gradle project.
Try to click ctrl +shift+O for import realated dependencies in your project.

Related

Trying to import maven project but some dependencies are missing in eclipse after the import

I have tried everything but nothing worked for me.
Some of maven dependencies are missing in the eclipse but are present in the pom.xml file and local repository
Any help would be much appreciated
Error Photo
Assuming you correctly imported the project, the problem could be that you don't have the repositories defined that contain the dependencies you want to use.
See https://maven.apache.org/guides/introduction/introduction-to-repositories.html for more information on how to define your repositories.
Ideally When you run a Maven build, then Maven automatically downloads all the dependency jars into the local repository but I ran into the similar problem before and updating the maven project did the trick for me project>maven>update project
below I have explained whole thing from build to updating with screen shots hoping it helps you
right click project> run as> maven build
above step should launch edit configuration and launch window, here set Goals: clean install
then click run
again right click on project>Maven>update project
check force update of snapshot/releases and click ok
finally, check under maven dependencies again if jars have downloaded
P.S. if you have JARs downloaded locally you can add them manually to your build path right click project>properties to resolve the issue

Unable to create project from archetype in Eclipse Luna

I am trying to create a simple Maven project in Eclipse Luna. As this is my first maven project so I am starting with a simple one. I am trying to crate a simple web project using the webapp-j2ee14 archetype.
While creating I found that this archetype is not present in archetype list. So I tried with Add Archetype option and Provided the following archetype options.
<archetype>
<groupId>org.codehaus.mojo.archetypes</groupId>
<artifactId>webapp-j2ee14</artifactId>
<version>1.3</version>
<repository>http://repo1.maven.org/maven2/org/codehaus/mojo/archetypes/webapp-j2ee14/1.3/</repository>
</archetype>
The above code snippet is basically from archetype-catalog.xml file in .m2 directory in my system, but I actually entered them from eclipse UI.
Now, when I am clicking finish it's giving me the following error...
I tried with few other repo url after searching google but getting the same error. Where can I get the correct repo url for this archetype??
Thanks in advance...
Add Remote Archetype in your eclipse it will show you that option. Following are the steps:
File--->New---> Maven Project---->Next--->Click on tab Configure
Separate window will open... Maven-->Archetypes-->Click on Add Remote Catalog--> In Catalog File type "http://repo1.maven.org/maven2/archetype-catalog.xml" and click on Apply and then Ok
Now in new Maven Project select Remote Archetype from Catalog and you will find webapp-j2ee14 option there.
I got the same problem and i was creating a simple Web App. I created the MAVEN project first then i deleted it and again when i created it i got this error. So i changed the version of archetype. I was using 2.16 version of the archetype that i was adding to my MAVEN project, changed it to latest 2.26 and it worked for me.
You can check the latest version from http://repo1.maven.org/maven2/archetype-catalog.xml
I got this problem as I have deleted a previously created project from Eclipse.
Later, I deleted the .metadata file and the project from workspace. Then this problem was resolved.
I got same issue, I have solved by manually removing unused pom.xml file at the working workspace or root of workspace directory.
I think the work space has messed up of some reason. These steps below may help
Close eclipse
delete the .metadata directory
Restart the eclipse, pointing to same workspace and try the process to create new maven project
or if this approach didn't work
switch to a fresh new workspace and try the same process to create your maven project
This is worked for me!
After working whole day, finally I found the solution. I just went to Eclipse marketlace(help-Eclipse marketplace) and updated maven from there. Now it works wonders. Earlier I was unable to install TestNG plugin from Eclipse marketplace, but now after updating maven from there, Testng plugin successfully installed in my eclipse luna.
I was trying to create a maven archetype quickstart and faced this issue, I have never created any maven project before so for those below is the steps you need to follow -
Go to to Run -> Run As -> Maven Install
In the project explorer right click on pom.xml file -> Maven -> Update project.
This will for sure resolve the issue.
Eclipse version I am using : 2021-09 (4.21.0)

How to build and run Maven projects after importing into Eclipse IDE

I am learning building a Java project in Eclipse using Maven. I created a Java project HelloWorld from
“maven-archetype-quickstart” template in a folder D:/maven_projects. Then to convert the Maven project to support Eclipse IDE, I navigated into the project folder and issued the commands:
mvn eclipse:eclipse and mvn package .
Then I imported the project in Eclipse and did the necessary Eclipse configurations like setting the Maven local repository in Eclipse classpath. Now the project in D:/EclipseWorkspace folder. I ran the project successfully in Eclipse printing "helloworld".
Now if I want to go on develop the project and for that reason want to add new dependencies in pom.xml in Eclipse, then the new jars are not added in classpath when I run the project.
So my question is after importing a Maven project into Eclipse how can I add more and more dependencies in pom.xml, then build and run the project? What is the recommended and efficient way to do this?
I would recommend you don't use the m2eclipse command line tools (i.e. mvn eclipse:eclipse) and instead use the built-in Maven support, known as m2e.
Delete your project from Eclipse, then run mvn eclipse:clean on your project to remove the m2eclipse project data. Finally, with a modern version of Eclipse, just do "Import > Maven > Existing project into workspace..." and select your pom.xml.
M2e will automatically manage your dependencies and download them as required. It also supports Maven builds through a new "Run as Maven build..." interface. It's rather nifty.
1.Update project
Right Click on your project maven > update project
2.Build project
Right Click on your project again. run as > Maven build
If you have not created a “Run configuration” yet, it will open a new configuration with some auto filled values.
You can change the name. "Base directory" will be a auto filled value for you. Keep it as it is. Give maven command to ”Goals” fields.
i.e, “clean install” for building purpose
Click apply
Click run.
3.Run project on tomcat
Right Click on your project again. run as > Run-Configuration.
It will open Run-Configuration window for you.
Right Click on “Maven Build” from the right side column and Select “New”.
It will open a blank configuration for you.
Change the name as you want. For the base directory field you can choose values using 3 buttons(workspace,FileSystem,Variables). You can also copy and paste the auto generated value from previously created Run-configuration. Give the Goals as “tomcat:run”. Click apply. Click run.
If you want to get more clear idea with snapshots use the following link.
Build and Run Maven project in Eclipse
(I hope this answer will help someone come after the topic of the question)
Dependencies can be updated by using "Maven --> Update Project.." in Eclipse using m2e plugin, after pom.xml file modification.
Just install the m2e plugin for Eclipse. Then a new command in Eclipse's Import statement will be added called "Import existing maven projects".
answer 1
Right click on your project in eclipse
go to maven -> Update Project
answer 2
simply press Alt+F5
after updating your pom.xml. This will build your project again and download all jar files
Right Click on your project
Go to Maven>Update Project
Check the Force Update of Snapshots/Releases Checkbox
Click Ok
That's all. You can see progression of build in left below corner.
When you add dependency in pom.xml , do a maven clean , and then maven build , it will add the jars into you project.
You can search dependency artifacts at http://mvnrepository.com/
And if it doesn't add jars it should give you errors which will mean that it is not able to fetch the jar, that could be due to broken repository or connection problems.
Well sometimes if it is one or two jars, better download them and add to build path , but with a lot of dependencies use maven.
If you are getting this error :in cucumber Exception
Cucumber Exception: java.lang.ClassNotFoundException:
cucumber.io.ResourceLoader :
then add following jar file to your pom.xml
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.1.8</version>
</dependency>
Run the maven build once and should be gone

Eclipse IDE behaves weirdly

I am getting a class not found exception for my Login Controller when I try to login to my application(It is a spring MVC Application). Before running the maven clean command the Application was running perfectly, I used maven clean and then again done a build using maven package command, suddenly it stopped working. I tried restarting the TomCat, re-deployed the application on TomCat, restarted the Eclipse IDE but nothing has worked so far.
Why this happens and what is the possible solution to this ??
Are you trying to run your project under Eclipse?
And does it generate source files?
If these are both true, you probably need to update the project config (select project or pom, right-click, Maven..Update..Project Configuration and Maven..Update..Project Dependencies).
The problem is that when Maven does a clean, it gets rid of the generated directories, which Eclipse observes and removes from your Build Path. But then when Maven rebuilds the directories, Eclipse doesn't notice it - you have to give it a hint.
Check your project for build errors and build path errors.
Make sure you've defined an M2_REPO classpath variable in Eclipse (Preferences - Java - Build Path - Classpath Variables).
If you're using the m2eclipe plugin, right-click your project and click on Maven - Update project configuration. That will configure an Eclipse build path for your project based on your pom dependencies.
If you're not using m2eclipse, execute mvn eclipse:clean eclipse:eclipse in your project folder. Then refresh your project in Eclipse.
What you haven't said is that you've checked and the missing class is in fact present.
A quick way to check is in the code editor SHIFT+CTRL+T and type the name of the missing class. Eclipse should not only show you the class if it exists, on highlighting the class, Eclipse should tell you which jar it is in.
Based on the info you have provided, I would say some dependecy in your POM has been removed by mistake or you need a newer version of some jar. If you find the class is not present, then you can figure out which jar you need by googling something like Maven 2 MyMissingClass jar that usually works for me.
Delete the .metadata folder in your eclipse workspace and then again open the workspace and import the required project.
This will solve your problem.
In .metadata folder it maintains the temporary copy of the project.
what worked in my case was simply removing the project from work space and importing it back again.
But I still don't know why it worked Vs why other things mentioned did not work (I tried updating dependencies in fact I removed all the dependencies from pom.xml and added everything again)

Source folders for a maven project in eclipse

I have a that uses maven... and I want to put it in my working environment with eclipse(Galileo)... the project is in a svn server, and I can create check out the project and everything looks OK. I even can run the unit test and everything is working there.
However, now that everything is there I wanted to work in the code, and oh surprise there are no packages in my project... I mean all the source code is in the src folder and browsing through it i can see all my files, ut if I open the files from there, the files are opened as text files with no coloring, but worst no help at all about errors in compilation.
I don't know what im I doing wrong now, because I had the same project in other machine and it was working well.
So here is what I did, please let me know if you notice if I did something wrong, miss any steps or anything that can help me:
In the SVN Repository (Using subclipse 1.6.10) I added my SVN Repository
Browsed to the folder where I have the pom file
Right Click> Check out as a Maven project...(Using m2eclipse 0.10.020100209)
Used the default options and finish.
The projects were created with no problem. I said projects because this maven project has modules, and each module became a project in eclipse.
Back in the java perspective, Right click in the project, Run as > maven test(Using JWebUnitTest, because I am testing a servlet)
BUILD SUCCESS!!
But as I said there is not packages so I can't really develop in this environment.
Any help??
Thanks!
When performing a svn checkout as maven project, m2eclipse writes what it does in a console window, accessible using the "console" panel, where there is a drop-down list of all available consoles. What does this console tells ?
Besides, if you can perform a maven test, you can also, in the maven menu (of your contextual menu) do a "update project configuration" which should do the same thing and configure eclipse for your project.
As a last test, is there a maven icon over your project ?
Have you tested your setup on command line with Maven ? Does a mvn package work without errors ? The location for the sources in Maven is src/main/java + Package name. Have you opened the project as a Maven project?
Thanks for your help, however I noticed that eclipse itself was behaving weird when I try to create a package there and I didn't have the option.
So I found out that for some reason that eclipse installation wasn't giving me any of the Java basic options.
So I download a new eclipse installation.. and I repeat the whole process and now is working...
No clue what was the problem with this eclipse because I was using it for other projects and I don't know when I lost the basic functionalities!
Thanks anyway!

Categories