1

I am trying to create my first ever Spring Boot application. The pom.xml that I am using here is:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>me.hahaha</groupId>
  <artifactId>SpringBootTutorial</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <!-- <name>SpringBootTutorial</name>
  <url>http://maven.apache.org</url> -->

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.9.RELEASE</version>
  </parent>

  <dependencies>
    <!-- JUnit -->    
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>

    <!-- Spring Boot Dependency -->
    <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
  </dependencies>

  <properties>
    <java.version>1.8</java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

</project>

However, eclipse complains saying:

No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]

I wonder what goal should my project have.

At this point, all I want is the project to build, compile and run and get the "Congratulations from BlogController.java" message on the localhost. I believe this isn't something specific to the project either (because it doesn't do anything much) and the pom.xml that I have posted above is pretty similar to the one they give in the docs for Maven.

Thanks.

Note: In case required, the tutorial that I am trying to follow is here.

Luke Woodward
  • 63,336
  • 16
  • 89
  • 104
J. Doe
  • 1,291
  • 2
  • 10
  • 19

1 Answers1

2

The goal you are looking for is package, which builds the executable package for your application.

Whenever you run maven with a goal every preceding goal is also executed. For a reference on which goal does what, see the official maven guide on the build lifecycle.

RenanB
  • 105
  • 1
  • 9
  • Thank you. That did the trick. Even [this](https://stackoverflow.com/a/12948760/8600195) was helpful. Could you please let me know what package is? Shouldn't it be the _name_ of the package, etc? Why just the word `package`? – J. Doe Apr 15 '18 at 20:40
  • Just the word `package`. The `goal` is your intent as the developer when invoking maven, and at this point your intent is to package your application into an executable. – RenanB Apr 15 '18 at 20:41
  • However, when I go to localhost, it doesn't show me the welcome message. Why so? – J. Doe Apr 15 '18 at 20:43
  • You need a server to host your application, even when serving from localhost. I suggest you take a look at http://tomcat.apache.org/ for a free and easy to use development server. – RenanB Apr 15 '18 at 20:45
  • Yes, I am aware about that. What I am saying is, isn't the application deployed on Tomcat by default as per [this](https://medium.com/@salisuwy/building-a-spring-boot-rest-api-a-php-developers-view-part-i-6add2e794646) tutorial? They are not doing anything specific for Tomcat. – J. Doe Apr 15 '18 at 20:49
  • When developing a project on an IDE such as IntelliJ, which that tutorial refers to, the IDE tends to hide multiple steps of the build process. In this case, the IDE sets up maven so the `deploy` goal copies the built executable to the tomcat directory, and invokes that instead of the aforementioned `package`. See this question for how to set it up manually https://stackoverflow.com/questions/15824096/how-to-deploy-war-with-maven-to-tomcat – RenanB Apr 15 '18 at 20:55
  • Oh, okay. Actually I am referring this link: https://spring.io/blog/2014/03/07/deploying-spring-boot-applications and it says that presence of a _controller application_ is enough for Maven to detect and create an instance of Tomcat. – J. Doe Apr 15 '18 at 20:57
  • Have you tried running the jar built by `maven package` with `java -jar .jar` ? – RenanB Apr 15 '18 at 21:04
  • No. Where do I run the command? The console does not allow me to type anything. It shows messages like 'Build successful'. – J. Doe Apr 15 '18 at 21:07
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/169039/discussion-between-renanb-and-j-doe). – RenanB Apr 15 '18 at 21:09