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
0
Upvotes
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:
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
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
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!"; } }
Run the project:
cd boot-test mvn spring-boot:run
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.