java spark framework with eclipse

20 views
Skip to first unread message

shinehah.ol...@gmail.com

unread,
Jul 29, 2016, 5:38:14 PM7/29/16
to Omaha Java Users Group
I saw the YouTube video on the Java Spark Framework at https://www.youtube.com/watch?v=q7Gbdr75kiU.

I would like to know how the presenter was able to get Spark to work with Eclipse.  Where can I go to get those instructions?

Matt Payne

unread,
Jul 29, 2016, 5:43:16 PM7/29/16
to Omaha Java Users Group
Hi Shinehah!   That is a great presentation on sparkjava[1].    

On their web page they mention the line for gradle.  I was able to get their hello world example working from within eclipse using gradle[2].   I just made a simple project and ran `gradle eclipse`, then imported the existing eclipse project and I was able to run HelloWorld from within eclipse.

Does this work for you too?  Thanks --Matt Payne

[2] 
% mkdir HelloJavaSpark
% cd HelloJavaSpark
% gradle init
:wrapper
:init

BUILD SUCCESSFUL

Total time: 2.403 secs

This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.9/userguide/gradle_daemon.html
% mkdir -p src/main/java/hello
% cat > src/main/java/hello/HelloWorld.java
package hello;


import static spark.Spark.*;

public class HelloWorld {
    public static void main(String[] args) {
        get("/hello", (req, res) -> "Hello World");
    }
}
% ls
build.gradle gradle gradlew gradlew.bat settings.gradle src
% ls -F
build.gradle gradle/ gradlew* gradlew.bat settings.gradle src/
% cat > .gitignore
gradle/
.gradle/
% git init .
Initialized empty Git repository
% git add .
% git commit -am 'Quickstart from http://sparkjava.com/documentation.html'
[master (root-commit) b262bc1] Quickstart from http://sparkjava.com/documentation.html
 6 files changed, 314 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 build.gradle
 create mode 100755 gradlew
 create mode 100644 gradlew.bat
 create mode 100644 settings.gradle
 create mode 100644 src/main/java/hello/HelloWorld.java
 % vim build.gradle
 % git diff
 diff --git a/build.gradle b/build.gradle
 index 9dd65aa..0ccd681 100644
 --- a/build.gradle
 +++ b/build.gradle
 @@ -7,9 +7,10 @@
   */

 -/*
 +
  // Apply the java plugin to add support for Java
  apply plugin: 'java'
 +apply plugin: 'eclipse'

  // In this section you declare where to find the dependencies of your project
  repositories {
 @@ -22,6 +23,8 @@ repositories {
  dependencies {
      // The production code uses the SLF4J logging API at compile time
      compile 'org.slf4j:slf4j-api:1.7.13'
 +    compile "com.sparkjava:spark-core:2.5"

      // Declare the dependency for your favourite test framework you want to use in your tests.
      // TestNG is also supported by the Gradle Test task. Just change the
 @@ -29,4 +32,4 @@ dependencies {
      // 'test.useTestNG()' to your build script.
      testCompile 'junit:junit:4.12'
  }
 -*/
 +
 %
 % gradle eclipse



On Fri, Jul 29, 2016 at 4:38 PM <shinehah.ol...@gmail.com> wrote:
I saw the YouTube video on the Java Spark Framework at https://www.youtube.com/watch?v=q7Gbdr75kiU.

I would like to know how the presenter was able to get Spark to work with Eclipse.  Where can I go to get those instructions?

--
You received this message because you are subscribed to the Google Groups "Omaha Java Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omaha-java-users-...@googlegroups.com.
To post to this group, send email to omaha-java-...@googlegroups.com.
Visit this group at https://groups.google.com/group/omaha-java-users-group.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages