EJB Vaadin 8

Hi guys, was trying to add a ejb bean to the backend of vaadin. can anyone guide me?

i have already added javaee-api-7.0.jar to the libraries.

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.example.NailiQuotation.samples.backend.ejb;

import javax.annotation.Resource;
//import javax.annotation.security.DeclareRoles;
//import javax.annotation.security.RolesAllowed;
import javax.ejb.SessionContext;
import javax.ejb.Stateless;

/**
 *
 * @author weilianghome
 */
//@DeclareRoles({"Sales", "Admin", "Production", "Logistics", "Designer", "Assembly", "Press", "Trim", "CTP", "Driver", "DTP"})
@Stateless
public class MySession  {

//    @EJB
//    private JobBeanLocal jobBean;

    @Resource
    private SessionContext context;

    public String sayHi() {
        System.out.println("in SayHi");
        String userName2 = context.getCallerPrincipal().getName();
        System.out.println("Usernme: " + userName2);
        System.out.println("User in role: regular_role " + context.isCallerInRole("Admin"));
        System.out.println("User in rolse: member " + context.isCallerInRole("Admin"));

//        System.out.println("User in rolse: member " + context.isCallerInRole("Admin"));
        return "Hihi";
    }

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    public String getResult() {
        return "This is My Session Bean";

    }

//    @RolesAllowed({"Sales", "Admin", "Production", "Logistics", "Designer", "Assembly", "Press", "Trim", "CTP", "Driver", "DTP"})
    public String sayHello() {
        String Username = context.getCallerPrincipal().getName();
        System.out.println("Context Name: " + Username);
        return sayHello(this.context);
    }

    public String sayHello(SessionContext context) {
        String Username = context.getCallerPrincipal().getName();
        System.out.println("Context Name: " + Username);
        /*
         * System.out.println("context.isCallerInRole(sales)" +
         * context.isCallerInRole("Sales"));
         * System.out.println("context.isCallerInRole(Admin)" +
         * context.isCallerInRole("Admin"));
         * System.out.println("context.isCallerInRole(production)" +
         * context.isCallerInRole("production"));
         * System.out.println("context.isCallerInRole(Logistics)" +
         * context.isCallerInRole("Logistics"));
         * System.out.println("context.isCallerInRole(designer)" +
         * context.isCallerInRole("designer"));
         */
        if (context.isCallerInRole("Sales") || context.isCallerInRole("Admin") || context.isCallerInRole("Production") || context.isCallerInRole("Logistics") || context.isCallerInRole("Designer") || context.isCallerInRole("Assembly") || context.isCallerInRole("Press")
                || context.isCallerInRole("Trim") || context.isCallerInRole("CTP") || context.isCallerInRole("Driver") || context.isCallerInRole("DTP")) {
            return ("Login Success");
        } else {
            return ("Login fail");
        }
    }

    /*
    @Override
    public List getRecentJob(int starting, int max) {
        return jobBean.getRecentJob(0, 100);
    }*/

}

[INFO]
 -------------------------------------------------------------
[ERROR]
 COMPILATION ERROR : 
[INFO]
 -------------------------------------------------------------
[ERROR]
 /E:/Eclipse/NailiQuotation/NailiQuotation-backend/src/main/java/com/example/NailiQuotation/samples/backend/ejb/MySession.java:[9,33]
 package javax.annotation.security does not exist
[ERROR]
 /E:/Eclipse/NailiQuotation/NailiQuotation-backend/src/main/java/com/example/NailiQuotation/samples/backend/ejb/MySession.java:[10,33]
 package javax.annotation.security does not exist
[ERROR]
 /E:/Eclipse/NailiQuotation/NailiQuotation-backend/src/main/java/com/example/NailiQuotation/samples/backend/ejb/MySession.java:[11,17]
 package javax.ejb does not exist
[ERROR]
 /E:/Eclipse/NailiQuotation/NailiQuotation-backend/src/main/java/com/example/NailiQuotation/samples/backend/ejb/MySession.java:[12,17]
 package javax.ejb does not exist
[ERROR]
 /E:/Eclipse/NailiQuotation/NailiQuotation-backend/src/main/java/com/example/NailiQuotation/samples/backend/ejb/MySession.java:[13,20]
 package javax.inject does not exist
[ERROR]
 /E:/Eclipse/NailiQuotation/NailiQuotation-backend/src/main/java/com/example/NailiQuotation/samples/backend/ejb/MySession.java:[19,2]
 cannot find symbol
  symbol: class DeclareRoles
[ERROR]
 /E:/Eclipse/NailiQuotation/NailiQuotation-backend/src/main/java/com/example/NailiQuotation/samples/backend/ejb/MySession.java:[20,2]
 cannot find symbol
  symbol: class Stateless
[ERROR]
 /E:/Eclipse/NailiQuotation/NailiQuotation-backend/src/main/java/com/example/NailiQuotation/samples/backend/ejb/MySession.java:[21,2]
 cannot find symbol
  symbol: class Named
[ERROR]
 /E:/Eclipse/NailiQuotation/NailiQuotation-backend/src/main/java/com/example/NailiQuotation/samples/backend/ejb/MySession.java:[28,13]
 cannot find symbol
  symbol:   class SessionContext
  location: class com.example.NailiQuotation.samples.backend.ejb.MySession
[ERROR]
 /E:/Eclipse/NailiQuotation/NailiQuotation-backend/src/main/java/com/example/NailiQuotation/samples/backend/ejb/MySession.java:[55,28]
 cannot find symbol
  symbol:   class SessionContext
  location: class com.example.NailiQuotation.samples.backend.ejb.MySession
[ERROR]
 /E:/Eclipse/NailiQuotation/NailiQuotation-backend/src/main/java/com/example/NailiQuotation/samples/backend/ejb/MySession.java:[48,6]
 cannot find symbol
  symbol:   class RolesAllowed
  location: class com.example.NailiQuotation.samples.backend.ejb.MySession
[INFO]
 11 errors 
[INFO]
 -------------------------------------------------------------
[INFO]
 ------------------------------------------------------------------------
[INFO]
 BUILD FAILURE
[INFO]
 ------------------------------------------------------------------------
[INFO]
 Total time: 1.038 s
[INFO]
 Finished at: 2018-03-18T23:45:40+08:00
[INFO]
 Final Memory: 13M/210M
[INFO]
 ------------------------------------------------------------------------
[ERROR]
 Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project NailiQuotation-backend: Compilation failure: Compilation failure:
[ERROR]
 /E:/Eclipse/NailiQuotation/NailiQuotation-backend/src/main/java/com/example/NailiQuotation/samples/backend/ejb/MySession.java:[9,33]
 package javax.annotation.security does not exist
[ERROR]
 /E:/Eclipse/NailiQuotation/NailiQuotation-backend/src/main/java/com/example/NailiQuotation/samples/backend/ejb/MySession.java:[10,33]
 package javax.annotation.security does not exist
[ERROR]
 /E:/Eclipse/NailiQuotation/NailiQuotation-backend/src/main/java/com/example/NailiQuotation/samples/backend/ejb/MySession.java:[11,17]
 package javax.ejb does not exist
[ERROR]
 /E:/Eclipse/NailiQuotation/NailiQuotation-backend/src/main/java/com/example/NailiQuotation/samples/backend/ejb/MySession.java:[12,17]
 package javax.ejb does not exist
[ERROR]
 /E:/Eclipse/NailiQuotation/NailiQuotation-backend/src/main/java/com/example/NailiQuotation/samples/backend/ejb/MySession.java:[13,20]
 package javax.inject does not exist
[ERROR]
 /E:/Eclipse/NailiQuotation/NailiQuotation-backend/src/main/java/com/example/NailiQuotation/samples/backend/ejb/MySession.java:[19,2]
 cannot find symbol
[ERROR]
 symbol: class DeclareRoles
[ERROR]
 /E:/Eclipse/NailiQuotation/NailiQuotation-backend/src/main/java/com/example/NailiQuotation/samples/backend/ejb/MySession.java:[20,2]
 cannot find symbol
[ERROR]
 symbol: class Stateless
[ERROR]
 /E:/Eclipse/NailiQuotation/NailiQuotation-backend/src/main/java/com/example/NailiQuotation/samples/backend/ejb/MySession.java:[21,2]
 cannot find symbol
[ERROR]
 symbol: class Named
[ERROR]
 /E:/Eclipse/NailiQuotation/NailiQuotation-backend/src/main/java/com/example/NailiQuotation/samples/backend/ejb/MySession.java:[28,13]
 cannot find symbol
[ERROR]
 symbol:   class SessionContext
[ERROR]
 location: class com.example.NailiQuotation.samples.backend.ejb.MySession
[ERROR]
 /E:/Eclipse/NailiQuotation/NailiQuotation-backend/src/main/java/com/example/NailiQuotation/samples/backend/ejb/MySession.java:[55,28]
 cannot find symbol
[ERROR]
 symbol:   class SessionContext
[ERROR]
 location: class com.example.NailiQuotation.samples.backend.ejb.MySession
[ERROR]
 /E:/Eclipse/NailiQuotation/NailiQuotation-backend/src/main/java/com/example/NailiQuotation/samples/backend/ejb/MySession.java:[48,6]
 cannot find symbol
[ERROR]
 symbol:   class RolesAllowed
[ERROR]
 location: class com.example.NailiQuotation.samples.backend.ejb.MySession

I would recommend you to study https://vaadin.com/start/v8-full-stack-javaee first. It demonstrates how to use Java EE backend with Deltaspike with Vaadin application, and how to use CDI also with UI classes.

Your errors say to me, that you have included Java EE API, but it is really just API. If you do not have Java EE compliant container (like Wildfly, Glassfish or TomEE) you do not have the implementation classes, and hence it is not working.

Your errors say to me, that you have included Java EE API, but it is really just API.

For compilation one needs just the API, implementation is provided in container.

package ejb;

import javax.ejb.Stateless;

@Stateless
public class MySessionBean {

}

This compiles just fine with only one dependency in pom.xml:

            <dependency>
                <groupId>javax</groupId>
                <artifactId>javaee-api</artifactId>
                <version>7.0</version>
                <scope>provided</scope>
            </dependency>

@Wei: It is impossible to give more help without more information about tools and configuration. Explaining how you “added javaee-api-7.0.jar to the libraries.” would be a good start. My guess is that you added the jar to the list of dependencies in eclipse, and then built with Maven, eg. you are a victim of the poor Maven integration in Eclipse.