A few things to understand about Java:
1) If you have a Maven project like this, code is divided between src/main/
and src/test/
directories. src/test/
is intended for unit tests. In your case, Spring2020Main
is not actually set up as a unit test, so I'm not sure what the author intended here.
2) When you compile using mvn clean install
, a jar (library) is built, but nothing from src/test
will be included in the output.
Generally, tests are executed during build. And this one would have been, except it's not set up as a real junit test, so it didn't run during build.
3) You can move the file from src/test/java
to src/main/java
and it will be built into your resulting jar.
4) In this case, when you run the JVM, you need to specify a classpath. This is a list of all libraries to include when the application starts. You also need to specify the (fully qualified) name of the class to run:
java -cp target/spring-2020-1.0-SNAPSHOT.jar Spring2020Main
...the above won't work directly since there are more unsatisfied dependencies (the top level pom.xml
brings in at least 3 other deps you'd also need to provide on the classpath).
As others pointed out, a solution could be to build a self-executing jar, but simplest for you would be to run this from an IDE:
Run this from IntelliJ. If you haven't installed it, install it.
1) File > New From Existing Sources
, find the directory where this is coned to.
2) When asked, Import Project from Existing Model
(Maven
)
3) When the Project view is available (alt-1), or View > Tool Windows > Project
, you can expand the structure till you find Spring2020Main
in the test directory.
4) Right-click it and select Run.
For me, it exposed a web server running at http://localhost:8888/test.html