Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing Spark without Maven

Tags:

spark-java

I am considering to use Spark in a Java course. My students do not know Maven, so I would like to let them install Spark without Maven. I downloaded this jar file and added it to my project, however, I got run-time errors about missing classes (such as slf4j). Is there a simple way to install Spark without Maven?

like image 312
Erel Segal-Halevi Avatar asked Mar 01 '26 16:03

Erel Segal-Halevi


1 Answers

Given this very simple POM:

<?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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.stackoverflow.spark</groupId>
  <artifactId>hello</artifactId>
  <version>0.1-SNAPSHOT</version>
  <description>Spark Hello</description>
  <inceptionYear>2017</inceptionYear>

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

</project>

A call to mvn dependency:tree yields:

[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building hello 0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ hello ---
[INFO] com.stackoverflow.spark:hello:jar:0.1-SNAPSHOT
[INFO] \- com.sparkjava:spark-core:jar:2.6.0:compile
[INFO]    +- org.slf4j:slf4j-api:jar:1.7.13:compile
[INFO]    +- org.eclipse.jetty:jetty-server:jar:9.4.4.v20170414:compile
[INFO]    |  +- javax.servlet:javax.servlet-api:jar:3.1.0:compile
[INFO]    |  +- org.eclipse.jetty:jetty-http:jar:9.4.4.v20170414:compile
[INFO]    |  |  \- org.eclipse.jetty:jetty-util:jar:9.4.4.v20170414:compile
[INFO]    |  \- org.eclipse.jetty:jetty-io:jar:9.4.4.v20170414:compile
[INFO]    +- org.eclipse.jetty:jetty-webapp:jar:9.4.4.v20170414:compile
[INFO]    |  +- org.eclipse.jetty:jetty-xml:jar:9.4.4.v20170414:compile
[INFO]    |  \- org.eclipse.jetty:jetty-servlet:jar:9.4.4.v20170414:compile
[INFO]    |     \- org.eclipse.jetty:jetty-security:jar:9.4.4.v20170414:compile
[INFO]    +- org.eclipse.jetty.websocket:websocket-server:jar:9.4.4.v20170414:compile
[INFO]    |  +- org.eclipse.jetty.websocket:websocket-common:jar:9.4.4.v20170414:compile
[INFO]    |  \- org.eclipse.jetty.websocket:websocket-client:jar:9.4.4.v20170414:compile
[INFO]    |     \- org.eclipse.jetty:jetty-client:jar:9.4.4.v20170414:compile
[INFO]    \- org.eclipse.jetty.websocket:websocket-servlet:jar:9.4.4.v20170414:compile
[INFO]       \- org.eclipse.jetty.websocket:websocket-api:jar:9.4.4.v20170414:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.229 s
[INFO] Finished at: 2017-10-14T21:33:25+02:00
[INFO] Final Memory: 12M/212M
[INFO] ------------------------------------------------------------------------

...Which basically gives you the minimal set of JAR files needed to start the simplest Spark application.

From there, you have several options:

  • Download the whole set of JARs and provide it to your students as a lib/ directory, and have them setup their CLASSPATH manually
  • Rebuild a single fat JAR with the contents of all required JARs
  • Spend some time during the first session to teach the basics of Maven (or Gradle) to your students

[Slightly off-topic] Admittedly, depending on the time available, I would definitely recommend the third option: Maven (or Gradle) and dependency management are here to stay for a while, and it looks like a must-have skill in this industry. Even if it only means providing your students with a simple POM and introducing them to mvn clean/package/install :)

like image 167
Mithfindel Avatar answered Mar 07 '26 11:03

Mithfindel