When I deploy ejb.jar and app.war separately, bean lookup works perfectly. Below is the syntax which I am using:
"ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName
where appName in blank
moduleName is ejb distinctName is blank
beanName is the bean to lookup
viewClassName is the class for the bean
But when I deploy ejb.jar inside an ear file and deploying app.war on a separate server. I am unable to lookup bean using above syntax.
When you deploy it as part of an ear, the appName part in that JNDI name, should correspond to the application name of the ear, which by default is the ear name without the .ear suffix.
P.S: If you are looking up the bean from within the same server (i.e. your client and EJB are both deployed on WildFly) then you don't need to use the WildFly specific ejb: JNDI naming scheme. You can use the portable Java EE spec supported JNDI naming scheme (which is described in the EJB spec as well as the Oracle EJB tutorials for Java EE6).
But when I deploy ejb.jar inside an ear file and deploying app.war on a separate server.
I just saw this part in your original question now. If my suggestion in the previous post about using the correct appName doesn't work, then please provide more details about how exactly it fails, including any exception stacktraces.