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

1

u/tonywestonuk Sep 12 '15

This post is currently rating between 0 and 1 score, (50% / 52%)

I think It has 10 votes up, and 10 votes down..... Thats pretty split down the middle!!

I just posted a 'hello world' for Java TomEE, showing how easy it is to get going. It works. I tested it did before I posted it. And this was enough to be voted down 10 times! Why would people in a java forum, probably many java evangelists, want to vote this down.... what harm is it causing.

The very first reply to this was:

Do you really want to play this dumb game?

Thats nice!

Why so much hostility?

5

u/avoidhugeships Sep 13 '15 edited Sep 13 '15

There is often a lot of hostility towards Java EE here but I am not sure why. Don't let it bother you too much. It gets tiresome correcting the same misrepresentations over and over again. Right now its all about spring boot, last year it was Spring Roo which you would not even know existed anymore reading here.

I have been stuck in Spring shops and its no fun for me either. It's not awefull, it just takes more work to get things done and is more complicated to maintain. I used to say that about Java EE but Spring has fallen behind in my opinion.

6

u/ciberon Sep 12 '15

I think this is not the kind of post people expect coming into this subreddit. If you made a reasonably detailed comparison between java ee and spring maybe people would enjoy having a discussion around it.

1

u/NimChimspky Sep 12 '15

Exactly this.

Instead of some dumb half baked, irrelevant hello world.

-2

u/doctorsound Sep 12 '15

Why so much hostility?

Mainly, your attitude. I'm all for the sharing of knowledge, and I the premise of your post is genuine, as I think Java EE is worth a shot (although, I personally don't feel the need in what I do), but you just seem really confrontational in both threads.

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.

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

2

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

I put classes into my app servers deployment directory, because thats where you put classes you want to be deployed.

Yes, obviously. But messing around with a deployed app in your app server's deployment directory is not the stuff that you should be teaching beginners, because there are a lot of pitfalls to that approach. Especially once you move past JSPs. No person in the modern world should be writing apps hosted in JSPs. That practice ended in the 1990s.

A beginner will not be blinded by the complexities of installing Maven etc.

Yes, as I demonstrated, Maven is very difficult to install. I'm still working on getting my eyesight back.

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

I also learned JSP this way. Not Servlets. Servlets are real classes that require you to recompile your classes yourself, using a tool. To understand packaging. That's when I learned about Ant and frameworks like Struts.

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!

Yes, I use tools. I'm not making fire by rubbing two sticks together, either.

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

No, you proved that you have to download a tool. And run that tool. And then you get a web app running in a web browser. Your tool is Tomcat, my tool is Maven. The significance of the difference is only in your own mind.

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.

1

u/lacosaes1 Sep 13 '15

No person in the modern world should be writing apps hosted in JSPs. That practice ended in the 1990s.

With the MVC specification I think JSP is going to resurge.

2

u/[deleted] Sep 12 '15

Or just install Maven, then clone a starter repo.

1

u/NimChimspky Sep 12 '15

you've posted this twice. sort your life out.

3

u/tonywestonuk Sep 12 '15

I posted it here first - I had a message telling me to post it to JavaHelp. Sort your own life out!

0

u/NimChimspky Sep 12 '15 edited Sep 12 '15

ok a tad strong on my part.

But its a bit weird, why do you feel the need to go around telling people how great java ee is ?

Most people have used it and form an opinion.

I don't like it, or spring btw. For many many different reasons. But hey it pays the bills.

-1

u/tonywestonuk Sep 12 '15

Why.... Because I have to use spring.... To pay the bills, as you say. And I hate it with a passion as every spring program I have worked on, even the spring-boot ones, end up as a huge spaghetti mess, with property files containing many database connection strings for live or dev, etc. Its complexity hell. I want to shout out from the treetops this is crap - LOOK OVER THERE AT JAVAEE- The grass is greener!!, and hopefully if I can get one other developer in the world to see what Java EE has to offer, rather than going to Spring Boot, or Golang, or Python, or PHP, etc, then it is worth it.

2

u/dorkquemada Sep 12 '15

So don't work with Spring then and specialize in Java EE. Nobody is holding a gun to your head I'd hope :)

I specialized in Java EE before because I liked it better and tend to work projects that fit my strengths, rather than showing up, hating it and probably not doing the best job I could.

Besides, a lot of the recent good stuff in Java EE was made possible by innovation done by Spring and others :)

1

u/tonywestonuk Sep 12 '15

Nobody is holding a gun to your head I'd hope :)

only the bank manager holding my mortgage deeds..... :-/ - Trust me I want to take my career this way this way.

2

u/NimChimspky Sep 12 '15

Why would someone choosing to develop in golang/python instead of Java upset you ?

Php, well yeah fair enough.

2

u/NimChimspky Sep 12 '15 edited Sep 12 '15

its not greener, most people think spring is better, after having used both (like me). Have you considered the possibility you are wrong.

Your example of complexity, a live and dev connection string in a property file doesn't make any sense; And compared to mess of the standard apis and documents is frankly absurd.

To clarify you can store live and dev strings in a sinlge property file/or different files if you want - it helps share projects. But you can store it somewhere else in your env like EE very simply.

This is the first time I've ever heard someone mention this as a problem. I really don't grok why you think spring is worse than ee for this.

1

u/elenim Sep 15 '15

δουλεύει !!!! Thanks !!!!!Makes sense compared to others