Cannot add Spark-Java as a Maven project in Eclipse - Not an Archetype?

696 views Asked by At

Following this patchy tutorial here:

http://sparkjava.com/documentation.html#getting-started

I added the following to a new archetype:

<dependency>
    <groupId>com.sparkjava</groupId>
    <artifactId>spark-core</artifactId>
    <version>2.2</version>
</dependency>

enter image description here

After creating a new project and giving it a name I get the following error:

Unable to create project from archetype [com.sparkjava:spark-core:2.2 -> ] The defined artifact is not an archetype

There is no Repo URL given on the documentation, so it must be under the nexus?

1

There are 1 answers

0
spark-java On BEST ANSWER

Create a new maven project and add

<dependency>
    <groupId>com.sparkjava</groupId>
    <artifactId>spark-core</artifactId>
    <version>2.2</version>
</dependency>

to your pom.xml file. When you're done it should look something like this:

<?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>your-group-id</groupId>
    <artifactId>your-artifact-id</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>com.sparkjava</groupId>
            <artifactId>spark-core</artifactId>
            <version>2.2</version>
        </dependency>
    </dependencies>

</project>

That's it. You can now create a Java class like this:

import static spark.Spark.*;

public class HelloWorld {
    public static void main(String[] args) {
        get("/hello", (req, res) -> "Hello World");
    }
}

and run it :)