r/java • • Sep 12 '15

JavaEE / TomEE - Hello World

Assuming that you already have the Java SDK installed, these are the steps to get a hello world program running in TomEE.

  1. Download / unpack Tomee.

    wget http://mirror.catn.com/pub/apache/tomee/tomee-1.7.2/apache-tomee-1.7.2-jaxrs.tar.gz tar -xvf apache-tomee-1.7.2-jaxrs.tar.gz

  2. Create folders to store your app.

    mkdir -p apache-tomee-jaxrs-1.7.2/webapps/helloworld/WEB-INF/classes cd apache-tomee-jaxrs-1.7.2/webapps/helloworld/WEB-INF/classes

  3. Create the HelloWorld.java

    vi HelloWorld.java

    import javax.ws.rs.*;

    @Path("/") public class HelloWorld {

     @GET
         public String home(){
         return "Hello World";
     }

    }

  4. Compile it.

    javac -classpath "../../../../lib/*" *.java

  5. Start the server.

    sh ../../../../bin/startup.sh

  6. Navigate to page http://localhost:8080/helloworld

0 Upvotes

24 comments sorted by

View all comments

2

u/sh0rug0ru__ Sep 12 '15 edited Sep 12 '15

Do you really want to play this dumb game?

Okay, here's a simple Spring Boot project, and we'll even start from scratch without having Maven installed:

  1. Download and install Maven.

    wget http://www.eu.apache.org/dist/maven/maven-3/3.3.3/binaries/apache-maven-3.3.3-bin.tar.gz tar xvzf apache-maven-3.3.3-bin.tar.gz

  2. Create a Spring Boot project. When prompted, choose option 1310 for a simple Spring Boot web project. There are preconfigured Spring Boot projects for JPA, AMQ, Websockets, Mongo, Redis, etc., etc. Specify groupId as boot-test, artifactId as boot-test and package as test.

    apache-maven-3.3.3/bin/mvn archetype:generate

  3. Add a controller at boot-test/src/main/java/test/jsp/HelloWorldController.java

    package test.jsp;

    import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*;

    @Controller public class HelloWorldController { @RequestMapping("/hello-world") public @ResponseBody String helloWorld() { return "Hello World!"; } }

  4. Run the project:

    cd boot-test mvn spring-boot:run

  5. Check out your app by navigating to:

    http://localhost:8080/hello-world

You could even commit this, because this is a real project and how you would actually use Spring Boot. You're not sticking classes into your app server's deployment directory for no useful purpose, demonstrating a practice that no sane person would use in the real world, all just to prove a useless point.

2

u/[deleted] Sep 12 '15

Or just install Maven, then clone a starter repo.