0

My question is: Why should I do EAR files ? Because I'm able to add ejb classes in simple war and it works. I added

import javax.ejb.Stateless;
@Stateless
public class HelloWorldBean {

    /**
     * Default constructor.
     */
    public HelloWorldBean() {
        // TODO Auto-generated constructor stub
    }


    public String hello() {
        // TODO Auto-generated method stub
        return "Hello World";

    }

}

and it's ok. It works. So I don't understand why should I add this class to the jar and create EAR package. Please explain me more details.

justcurious
  • 839
  • 3
  • 12
  • 29
FoxNet
  • 518
  • 5
  • 17
  • Are you able to access these EJBs using jndi names ? Or are they deployed onto your AS with given jndi name ? When you attach files in your war then you normally access them like plain java files, not EJBs. – SacJn Nov 19 '15 at 12:14
  • Have a look at this answer: http://stackoverflow.com/a/1594723/982149 – Fildor Nov 19 '15 at 12:15
  • 2
    Possible duplicate of [.war vs .ear file](http://stackoverflow.com/questions/1594667/war-vs-ear-file) – Jens Schauder Nov 19 '15 at 12:16
  • maybe I just don't understand the main reason for use EJB. I didn't try use JNDI but in servlet i used @EJB HelloWorldBean myBean construction so it was ok – FoxNet Nov 19 '15 at 12:45
  • i found more good topic http://stackoverflow.com/questions/6968587/ear-vs-separate-ejb-war – FoxNet Nov 19 '15 at 12:50

1 Answers1

0

In J2EE application, modules are packaged as EAR, JAR and WAR based on their functionality

JAR: EJB modules which contain enterprise java beans (class files) and EJB deployment descriptor are packed as JAR files with .jar extenstion

WAR: Web modules which contain Servlet class files, JSP Files, supporting files, GIF and HTML files are packaged as JAR file with .war (web archive) extension

EAR: All above files (.jar and .war) are packaged as JAR file with .ear (enterprise archive) extension and deployed into Application Server.

Community
  • 1
  • 1
Abdelhak
  • 8,299
  • 4
  • 22
  • 36