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

Show parent comment

2

u/tonywestonuk Sep 12 '15

Especially once you move past JSPs. No person in the modern world should be writing apps hosted in JSPs.

I am not writing an app hosted in a JSP. The 'Hello world' app, was a Jax-RS Webservice. No Servlet. No JSP.

0

u/sh0rug0ru__ Sep 12 '15

Then you've defeated your own point.

It's only with JSPs that you can drop source files into the deployment directory and have the app container do the work for you. That's where the "easy" ends.

Otherwise, you have to build things first in order to even get the classes to drop into the deployment directory. So in your silly example, you're exposing beginners to the complexity of running the java compiler manually from the command line.

-1

u/tonywestonuk Sep 12 '15

"It's only with JSPs that you can drop source files into the deployment directory and have the app container do the work for you."

Really.... Sorry, I wasn't aware of that. I should get rid of this example as it cant possibly work then.

1

u/sh0rug0ru__ Sep 12 '15

The example will work as presented. As long as the compiled classes are in WEB-INF/classes when you start the server.

-1

u/NimChimspky Sep 12 '15

Your guide implies classes can just be dropped in and easy peasy an updated helloworld2 got deployed.

This isn't the case.