0

I'm learning Java EE. I'm getting a grasp on CDI, dependency and context injection. Doesn't seem too hard for now.

Now I want to try and actually write some code. I installed NetBeans (with GlassFish and everything else) and I'm kinda stuck now.

My book (Beginning Java EE 7 by Goncalves) has a nice simple example that demonstrates EJB and context/dependecy injection, annotations, interceptors, producers, etc... In the book, he just wrote the code he needed, added the bean.xml, and that was is. He used maven, so he added an explicit dependency to Weld and he was able to instantiate it in a main class, and run it without an application server.

But when I want to create a new project, I'm essentially given two choices, Web Application and Enterprise Application.

A WebApp lets me use all of the Java EE specification, the application server takes care of instantiation, life cycles, clean up for me. Good, the point is that in order to run my code I need a web page (with a servlet and an html page). Is there anyway I can avoid this and have a "normal" application? (Point is, I quite dislike writing HTML code, I would rather use a command line app anyday).

I tried to create an enterprise app, but it creates three projects (EJB, web, and another). I honestly don't know what to touch here, and the presence of the web project kinda tells me that I would still need to write html and serlvets.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Paul
  • 473
  • 6
  • 19

3 Answers3

1

The difference between "web" and "enterprise" applications has been answered numerous times, e.g. here.

Generally, you don't need an enterprise application, unless you know that you do.

Now, on your specific remarks, what would your application do without HTTP connections? Are you looking for JMS, or something like that? In that case, you could pack only your EJBs in a JAR and deploy that to your application server.

Otherwise, if you're simply looking for testing things out, you can go the easy route of testing out the auto-generated web application and ignore the web part of it.

Community
  • 1
  • 1
JChrist
  • 1,734
  • 17
  • 23
  • What I would like to do (for now, anyway) is write a small interactive application (to learn how things work) without having to deal with HTML pages and connections. But if possible, I would still like to use GlassFish in order to manage things for me, I just want to print menus and stuff on the console. – Paul Feb 05 '17 at 20:41
  • 1
    `Java EE` was not meant to be used as such, so your way will not be very easy. Might I suggest you follow a tutorial, possibly Oracle's: https://docs.oracle.com/javaee/7/tutorial/ – JChrist Feb 05 '17 at 20:46
  • 1
    Oh ok, I understand now. I was actually wondering if I was just trying to do something that wasn't intended. I'll just suck it up and write a couple of html pages I guess. – Paul Feb 05 '17 at 20:52
  • Netbeans contains a JSF page generator if you already have JPA entities to model your data. Otherwise, I recommend using Primefaces, which is a rich component library for Java Server Faces, and provides lots of documentation and examples: http://primefaces.org/showcase/ui/button/button.xhtml – OndroMih Feb 07 '17 at 20:24
0

Your question contains the answer "He used maven" and you are trying "Web Application and Enterprise Application." you are doing something that wasn't intended, if you are still interested in Netbeans/Enterprise Apps there is an option to create Maven applications in the Netbeans IDE.

I haven't gone through the tutorial but you can have a look: https://netbeans.org/kb/docs/javaee/maven-entapp.html

Cheers

alkathirikhalid
  • 887
  • 12
  • 18
0

If you want to create Maven projects in Netbeans, you have to select the maven category to choose from. There you'll find a maven web project template. Do not confuse this with the other categories in the Create project dialog - they mostly create a project in an Ant-based format, which is specific to Netbeans.

You can also open any existing maven project in Netbeans. You can find many Java EE sample projects in this github repository to start with.

OndroMih
  • 7,280
  • 1
  • 26
  • 44