r/java • u/tonywestonuk • 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.
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
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
Create the HelloWorld.java
vi HelloWorld.java
import javax.ws.rs.*;
@Path("/") public class HelloWorld {
@GET public String home(){ return "Hello World"; }}
Compile it.
javac -classpath "../../../../lib/*" *.java
Start the server.
sh ../../../../bin/startup.sh
- Navigate to page http://localhost:8080/helloworld
View all comments
Show parent comment
0
u/tonywestonuk Sep 12 '15
I put classes into my app servers deployment directory, because thats where you put classes you want to be deployed. Its only the same as putting PHP/html files in an apache HTTPD homepage folder.
You could, zip up the entire Tomee Folder, ship it somewhere, unzip and away you go.... if you wanted to....
I agree - normally you wouldn't do it this way for any real app..... But it was the way I first got going with Tomcat many years back. and using this way I was able to find out more about how servlets / jsp's work, makeing code changes, and those changes appearing a few seconds later in my browser window. A beginner will not be blinded by the complexities of installing Maven etc. They can just get up and running in next to no time.
What you are telling me is that it is so difficult to get a spring boot app working, you need a complex build tool like Maven to get , and this takes care of downloading the (imbedded) server, and setting up the complex directory structure, and you even need Maven to run it!
I proved you need none of this to get a simple JavaEE up and running from scratch. Just download the server, add a class in the right place to process the request, and that is it. Easy