Issue
I'm trying to find the quickest way to get a simple JUnit test up and running with IntelliJ IDEA and Maven. This is what I do:
File > New Project
Maven > Create from Archetype > org.apache.maven.archetypes:maven-archetype-quickstart
Give it a unique GroupId and ArtifactId ("testingmaven")
Give it a project name ("testingmaven")
Click Finish
At this point, I get the following file structure:
project
|_src
|_main
|_java
|_testingmaven
|_App.java
|_test
|_java
|_testingmaven
|_AppTest.java
But I can't run anything. When I put a simple JUnit test in AppTest.java and click "Build > Run" it forces me to update configurations. It doesn't seem to recognise my files as Java.
I just want to be able to start a Maven project, write a simple JUnit test, and run the test.
I'm coming from Ruby, so I know I'm just not used to package organisation and IDE configuration.
Am I missing something?
Is it because of the archetype I'm starting with?
When I tried to start a Maven project without an archetype, I didn't get pom.xml
.
Is there a better archetype for my purposes?
Solution
The fasters way for creation Maven project is generating it from a console -> import to IDE.
for this purpose you can use maven-archetype-quickstart
archetype.
Just execute following command:
mvn archetype:generate -DgroupId={com.mycompany.app} -DartifactId={my-app-name} -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
You have to replace {...}
params with your data, like project name and packages.
maven-archetype-quickstart
automatically adds junit
to pom file and creates test stub. By default, junit version is 3. My suggestion is to update it to 4.
After this you can easily import this project with Intellij Idea:
File > New > Project from Existing Sources > select pom.xml (double click) > Next ... > Finish
Also don't forget about formatting shortcut Ctrl+Alt+L
Useful link:
How to create a Java project with Maven
Answered By - catch23