0
votes

Im following a RESTful web services tutorial from http://www.concretepage.com/spring-4/spring-4-rest-web-service-json-example-tomcat. Is has spring framework dependencies. Instead of downloading the binaries and putting it in the lib dir i have included a dependency in pom.xml like

    <?xml version="1.0" encoding="UTF-8"?>
<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>com.concretepage</groupId>
<artifactId>Spring4</artifactId>
<version>1</version>
<packaging>war</packaging>

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

    <dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.0.3.RELEASE</version>
    </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>
    </dependencies>   

</project> 

when i right click on pom.xml - Run>Maven build it gives me the following error in the console

enter image description here

[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format : or :[:]:. 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.

I have no prior experience of build mechanisms of java(ant,maven,gradle etc) please guide me how can i successfully create a war file from the abv mentioned tut.

Regards

2

2 Answers

1
votes

Try to add your project-name. Set the "packaging" to "war"; the packaging by default is "jar". (the group-id is by default your parent's, and so does the version)

<artifactId>your.project.name</artifactId>
<packaging>war</packaging>

When you try to build it using Maven outside Eclipse - does it work? (from command line, mvn clean install...)

BTW what version of eclipse are you using? in Kepler i cannot see the option of Run>build with maven. enter image description here

Try to go to "preferences" screen, and see the Maven's configurations: enter image description here

1
votes

Generally you need to create a build configuration for the project first before you can simply select Run>Maven build. Creating a build configuration basically means defining what maven goals should be executed during a build.

To do this you need to do the following:

  • select Run>Maven build...
  • in the window that appears give the build configuration a name and then define which goals should be run (fairly standard goals are clean install - as shown) enter image description here
  • click on Apply and then Run - this will then close the window and run the build

Now in the future when clicking on Run>Maven build this configuration will be selected by default.