Initializing and running springboot project using maven in Intellij? - java

I get a spring boot with maven project from github, which works well in my teammates computers. I am using Intellij idea and I am confused about how to run it in my computer. Should I initialize a project or can I just use the project directly by open folder?
In edit configuration part, I choose maven and the directory containing pom.xml. In that case it gives noGoalsSpecified error. So should I include a goal in command line part of edit configuration. In short, how to run the project?

Related

Does creating a folder in default maven directory structure offered by eclipse lead to any issues?

I've recently started learning Spring REST. As part of my learning process, I developed a simple Hello World application using Maven. The directory structure of maven offered by Eclipse doesn't contain the "
java" folder in src/main. So, I added it explicitly. It turns out the application gives me a 404 error as you can see in the below image. I'm sure this has something to do with the class path. As I'm new to maven I don't understand the concept of the classpath.
But in the second image, I created the project using "co.ntier" (maven archetype for Spring MVC). The directory structure of this archetype has got the java folder which is why when I run the application I'm able to get the output.
How to add or configure maven so that every time I create a new maven project, the directory structure will have the java folder? Please help me.
I recommend to always create a Maven project from an archetype.
You can e.g. use the quickstart archetype for a simple project.
The presence of a "java" folder has nothing to do with whether an application can successfully serve something at a particular url. They are not directly related. This also has nothing to do with the classpath.
However, the red mark on the project indicates an error, and as the DEFAULT location for compilable source in a Maven project is "src/main/java", it seems clear that the lack of the "java" folder results in the project not being deployed, which IS why you get a 404.
In short, if you have red marks in the project, it's not going to deploy.

How to make Visual Studio recognize Spring Boot packages and get IntelliSense?

I have created a Spring Boot application using Spring Intializr extension of VS Code.
Configuration, Build Tool : maven, Language : Java, groupId : com.example, artifactId : springdemo, Spring boot version : 2.0.3, I have selected 2 dependencies which are Spring MVC and Spring DevTools Core from the dropdown.
Here is the screenshot Screenshot of the selected dependencies
After importing it and opening the folder structure Project Structure after vs code imports the maven project and opens up the folder
After this I ran a command
chmod 777 mvnw
to give permission to the gradle wrapper and after that
./mvnw clean install
This seems to work fine logs after the ./mvnw clean install command
This is my pom.xml
My pom.xml contains
Here is the difference : My VS Code project does not contain the maven dependencies folder as in case of eclipse and even after install all the packages vs code does not seem to recognize the packages and shows error
errors in vs code
This is how my eclipse project structure look like eclipse project structure contains the maven dependencies
The final result is a running project. The project runs even from vs code by ./mvnw spring-boot:run
but I am unable to get any kind of IntelliSense from VS Code and although eclipse works but I need to use VS Code. Please help.

Run maven web project with JSP debugging on tomcat with IntelliJ Idea

I'm transitioning from Eclipse to IntelliJ Idea and having some trouble getting my Maven Web project running as I'd like. In Eclipse, I ran it using mvn tomcat:run, which worked fine with JSP debugging. In IntelliJ, I created a run configuration to use this command, and it works, but JSP debugging doesn't work.
I tried to find info on getting JSP debugging to work on IntelliJ, and the only info I found involved setting up a Tomcat server in IntelliJ, not using Maven's tomcat with mvn tomcat:run. The problem is, I can't figure out how to do this without IntelliJ using it's own builder instead of building the project with Maven. I can add Maven goals like "mvn compile", but when I set it to deploy exploded war, and adds 'build myproject:war exploded artifact' to the build queue, which calls IntelliJ's builder.
IntelliJ's builder takes forever to build my project. I've never even let it finish. To be fair, the project is huge, but Maven builds to fairly quickly. Also, everyone in my company is using Maven to build it, so I need to use Maven as well.
Can anyone help me either get JSP debugging working using mvn tomcat:run, or on an Intellij managed Tomcat with the project built by Maven?
In IntelliJ you can easily debug a "remote" tomcat instance (one running in a different JVM than IntelliJ):
Run -> Edit Configuration -> "+" -> Tomcat Server -> Remote
That will create a new run configuration. Look at the information on the "Startup/Connection" tab for the parameters to add to the tomcat JVM. Mine are:
-Xdebug -Xrunjdwp:transport=dt_socket,address=57813,suspend=n,server=y
Finally, start tomcat by launching the required maven command. Then run the above run configuration (click debug button).

Build play! project with maven

I am using play 1.2.4 to create a web app. It works together with some other applications which are maven projects: they are compiled and resolved (dependencies) with maven.
Now I need to modify my play app so it can also be compiled and started with maven.
Therefore I download maven (3.0.4), installed the maven modul and did everything according to https://github.com/wangyizhuo/play-maven and http://www.playframework.org/modules/maven-head/home
I manage to automatically create a pom file in my project. The problem is that the jars from the play framework are not copied into the lib-folder and when I try to execute mvn package they are missing.
Is there a way to get the maven module to work properly? If not, is there another possibility to compile and start the project from maven (i.e. intermediate ant-file that can be executed by maven?)
Many thanks in advance!
This explains it pretty well. I havnt looked at the module you are refering too, but this shows you how you can create tasks and inculde directories in your build.
Do you need to use maven to build/run it? If not it looks like there is a community contributed extension that allows you to use maven from within play.

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)

Categories