Eclipse troubleshooting

Code not accepting the changes

If you do changes and restart the app, it won’t get the changes. You should tick the Project-> Build automatically so that it will actually compile.

Advertisements

Eclipse debugging

Debugging is used to find the place where the bug occurs. This is done by setting up break points in the code, so when you run your application it will run the code up until point where you put your first break point. Also debugging in Eclipse provides with window that shows the values of the variables at the current breakpoints.

F8 is most used button while debugging since it allows to resume to next break point. Dev should focus most on proper places to put the break points.

Java annotations

Java annotations are one of the main ease-of-development features introduced in JDK 5. Annotations are like meta-tags that you can add to your code and apply to package declarations, type declarations, constructors, methods, fields, parameters and variables. They provide a helpful way to indicate whether your methods are dependent on other methods, whether they are incomplete, whether your classes have references to other classes, and so on.

Dependecny Injection(DI) to Access EJBs

There are two ways to access the EJBs: 1. JNDI 2. DI

Advantages:

  1. Removes JNDI lookups
  2. DI can inject this:
    1. @EJB
    2. @Resource, @PersistenceContext, @EntityManager

DI is supported within:

  1. Enterprise Java Beans
  2. Servlets/JSPs/Filters/Managed Beans/
  3. Applicaiton Client Container clients

Annotations:

@EJB

Example of dependency injection EJB -> Servlet

// this is servlet
@WebServlet(name="DICalculator", urlPatterns = {"/DICalculator"})
public class DICalculatorServerlet extends HttpServlet {

// Line below injects RemoteCalculator bean into this servlet
@EJB
private RemoteCalculator calculator;
// now we can use the injected object
int sum = calculator.multiply(5,5);
RequestDispatcher dispatcher = request.getRequestDispatcher("calc-result.jsp");

@Resource

JNDI

Java Naming and Naming Interface if part of Java SE:

  1. Standard API to interact with naming and directory services
  2. Provide the ability to look up things in a “registry”
  3. Used in enterprise solutions to locate resources such as EJBs, JMS queues or Web Services

JNDI resources are organized in tree structure:

  1. Analogues to the folder structure of a computer’s file system
  2. Supports events, lookups, and complex searching against structure

App->JNDI->JNDI IMPL->DS

Finding EJB with JNDI uses four key concepts:

  1. Context
  2. Initial context
  3. Path & Name
  4. Search

Simple JNDI lookup:

String jndiPath = com.development.tutorials.ejb3.RemoteCalculator;

try{

   calculator = (RemoteCalculator) c.lookup(jndiPath);

}

Problems with JNDI
1. Keep track of JNDI path
2. Bean name

Accessing Session Beans

After we implemented the session beans, we should be able to access it.

EJB interactions:

A client for and EJB can be:

  1. Java EE Application Client
  2. Java EE component (JSP,Servlet,JSF,EJB)
  3. Any java object
  4. Java application

Client finds a proxy to interact with an EJB using:

  1. Java naming and directory interfaces(JDNI)
  2. Dependency Injection(used most of the time)

Steps for interacting with with and EJB(3-step plan)

  1. Declare the reference for the EJB interface
  2. Get the EJB “instance”
    1. using JNDI for remote clients or legacy EJBs
    2. using DI for local clients or application clients
  3. Invoke methods on the interface