Issue
I assume that additional dependencies are needed, but I can not understand exactly what. I appreciate everyone's help.
My pom file 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>com.spark</groupId>
<artifactId>spark</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<name>M101J</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.19</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>Spark repository</id>
<url>http://sparkjava.com/nexus/content/repositories/spark/</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.spark.SparkHomework</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
When I try to run my project with command:
mvn compile exec:java -Dexec.mainClass=com.spark.SparkHomework
I have the issue like this:
Unknown lifecycle phase ".mainClass=com.spark.SparkHomework". 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.
My class named as SparkHomework (package named as com.spark) is :
package com.spark;
import freemarker.template.Configuration;
import freemarker.template.Template;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import spark.Request;
import spark.Response;
import spark.Route;
import spark.Spark;
import java.io.StringWriter;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
public class SparkHomework {
private static final Logger logger = LoggerFactory.getLogger("logger");
public static void main(String[] args) throws UnknownHostException {
final Configuration configuration = new Configuration();
configuration.setClassForTemplateLoading(
SparkHomework.class, "/");
Spark.get(new Route("/") {
@Override
public Object handle(final Request request,
final Response response) {
StringWriter writer = new StringWriter();
try {
Template helloTemplate = configuration.getTemplate("answer.ftl");
Map<String, String> answerMap = new HashMap<String, String>();
answerMap.put("answer", createAnswer());
helloTemplate.process(answerMap, writer);
} catch (Exception e) {
logger.error("Failed", e);
halt(500);
}
return writer;
}
});
}
private static String createAnswer() {
int i = 0;
for (int bit = 0; bit < 16; bit++) {
i |= bit << bit;
}
return Integer.toString(i);
}
}
Solution
SOLVED!
In Powershell need to add quotes like -D"exec.mainClass"
. In command prompt - all is okay without them. Thanks everyone!
command prompt and powershell.
Answered By - invzbl3