Specified library jar EJBRemoteInterface.jar does not exist - javabeans

I created class library project named EJBRemoteInterface. Then I created Enterprise applications named it EntAppEJB .I added the Remote reference EJBRemoteInterface applications with EJB Applications . Inside the applications I added session bena which invoke getString () methods . Then I created enterprise client applications to access the getSting methods . I deployed the EJB Applications Into glassfish server . But when i run the client application or tired deployed I am getting following error in server log .#
Exception while deploying the app [EntAppClient] : Specified library jar EJBRemoteInterface.jar does not exist: C:\Users\Khundokar%20Nirjor\Documents\New%20Folder%20(5)\EJBRemoteInterface\dist\EJBRemoteInterface.jar]
Here is the interface .
#Remote
public interface MySessionRemote {
String getResult();
}
Here is the Bean class.
#Stateless
public class MySession implements MySessionRemote {
public String getResult() {
return "This is My Session Bean";
}
}
Here is the client code .
import ejb.MySessionRemote;
import javax.ejb.EJB;
public class Main {
#EJB
private static MySessionRemote mySession;
public static void main(String[] args) {
System.err.println("result = " + mySession.getResult());
}
}
Here is the code when i tried to deploy the applications or run it ..
ant -f "C:\\Users\\Khundokar Nirjor\\Documents\\New Folder (5)\\EntAppClient" -Dnb.internal.action.name=run -DforceRedeploy=false run
init:
EJBRemoteInterface.init:
Deleting: C:\Users\Khundokar Nirjor\Documents\New Folder (5)\EJBRemoteInterface\build\built-jar.properties
EJBRemoteInterface.deps-jar:
Updating property file: C:\Users\Khundokar Nirjor\Documents\New Folder (5)\EJBRemoteInterface\build\built-jar.properties
EJBRemoteInterface.compile:
EJBRemoteInterface.jar:
deps-jar:
compile:
library-inclusion-in-archive:
Building jar: C:\Users\Khundokar Nirjor\Documents\New Folder (5)\EntAppClient\dist\EntAppClient.jar
dist:
pre-run-deploy:
Distributing C:\Users\Khundokar Nirjor\Documents\New Folder (5)\EntAppClient\dist\EntAppClient.jar
GlassFish Server, deploy, null, false
C:\Users\Khundokar Nirjor\Documents\New Folder (5)\EntAppClient\nbproject\build-impl.xml:988: The module has not been deployed.
See the server log for details.
BUILD FAILED (total time: 0 seconds)
Here is the screen shot the ejb deployment
.
Here is the screen shot of the project .
Here is the screen shot the error .

Related

How to inject EJB from different EAR in same glassfish

I have been trying to implement this design for couple of days ago and had no success. (before continuing I tell that I have read this article "How can I inject an EJB from an other application on the same GlassFish Server?" and other than glassfish-ejb-jar.xml I tried everything in it )
I have 2 ear application. test.ear is my main app which I want to test it, but I don't want to add any remote interfaces in this project, so I created another .ear(automation.ear) which contains remote interfaces and inject EJBs from test.ear . so my standalone application calls automation app and can not access test application directly.
each application contains these modules: entities, ejb , ear (for example automation application contains :automation-entities, automation-ejb, automation-ear)
here is my journey :
(I deployed test.ear before all these attempts)
-first try: I added test.ejb with ejb type as a maven dependency to automation-ejb pom.xml and injected EJB of test.ear in one of the beans of automation project and gave it a mappedName; it worked however I realized that it is a false positive and it actually doesn't go to the implementation of test.ear. it uses the copy it has (because of dependency)
- second try: I added a plugin in pom.xml of test.ear to create ejb-client for me (which only contains the interfaces and not the implementation) and added this .jar to automation pom.xml as a dependency, then injected the ejb gave it mappedName and try to deply ; well it complained about not finding the class!--> can't deploy
- third try: I added a copy of the interface I wanted to use(from test.ear) in automation.ear and removed the dependencies in pom.xml of automation. injected EJB and gave it the mappedName; tried to deploy and no luck ! still can't find the class--> can't deploy
Here are my classes:
test.ear application
package com.ericsson.test.service;
import javax.ejb.Local;
#Local
public interface TestService1 {
public String TestMethod1();
}
//////////////////////////////////////////////////////
package com.ericsson.test.service;
import javax.ejb.Local;
import javax.ejb.Stateless;
#Local(TestService1.class)
#Stateless(name = "TestService1")
public class TestServiceBean1 implements TestService1{
#Override
public String TestMethod1() {
return "Test Method1";
}
}
automation.ear application
#Remote
public interface RemoteInterfaceTest{
public void doSomething();
}
////////////////////////////////////////////////////////////////////////
package com.ericsson.test.service;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.naming.InitialContext;
#Singleton
#Startup
public class RemoteInterfaceTestBean implements RemoteInterfaceTest {
#EJB(mappedName = "Test-Server-Local/test-ejb-0.0.1-SNAPSHOT/TestService1/local")
private TestService1 testService1EJB;
#PostConstruct
public void doSomething() {
try {
InitialContext ic = new InitialContext();
TestService1 service1 = (TestService1) ic
.lookup("java:global/Test-Server-Local/test-ejb-0.0.1-SNAPSHOT/TestService1");
System.out.println(service1.TestMethod1());
} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println("OOOOOOPPPPPPSSSSSSSSS ! First try");
}
try {
testService1EJB.TestMethod1();
} catch (Exception e) {
System.out.println("OOOOOOPPPPPPSSSSSSSSS ! Second try");
}
}
}
and this is the exception I get:
SEVERE: Exception while deploying the app [automation-csdp-remote] : Cannot resolve reference Local ejb-ref name=com.ericsson.test.service.RemoteInterfaceTestBean/testService1EJB,Local 3.x interface =com.ericsson.test.service.TestService1,ejb-link=null,lookup=,mappedName=Test-Server-Local/test-ejb-0.0.1-SNAPSHOT/TestService1/local,jndi-name=,refType=Session
I have tried played with it like 1000 times, I checked the glass fish and the class is there, why it can not find it ? any idea would be greatly appreciated.
I am using EJB 3.x , glassfish 3.1.2 , maven 3.0.5, eclipse kepler

start application (from jar) on Weblogic startup

I'm using Weblogic 12c, I need to run app before/with the web app starts.
the app should fetch information and write it to db.
I read that in previous versions of WL programmers used to work with ApplicationLifecycleListener, but it is deprecated now.
I'm compiling the project to ear file.
I also tried to use ejb3.2 eager singleton, but it didn't worked.
Is there any working alternative?
I solved the issue by creating EJB as the following:
#Singleton
#Startup
public class StartupBean {
#PostConstruct
private void startup() { ... }
#PreDestroy
private void shutdown() { ... }
...
}
Creating the EJB Singleton instances is one of the Weblogic life cycle init calls, I put my java code under startup() method.

Unit Testing from within Play-Module (JPA, eclipse PersistenceProvider)

My application is based on playframework and contains multiple modules.
The database interaction is handled trough JPA (<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>)
My task is to cover one of these modules with unit-tests.
Unfortunately running the "play test" command with unit tests provied on module-level results in the following Exception:
javax.persistence.PersistenceException: No Persistence provider for EntityManager named defaultPersistenceUnit
Persistence-Provider is defined globaly (outside of the Module) in conf/META-INF/persistence.xml
copying the global persistence.xml to the module doesn't fix the issue.
Placing the tests outside of the module (in global test directory) and execute them works flawless presuming that there are no other tests within modules.
Can someone explain me why the Error comes up? Is there any way to have working JPA-capable tests on module level?
Thanks in advance
Urs
I had the same problem running JUnit tests from my play application in Eclipse.
To solve this issue you need to make the folder conf available to the all project.
Project Properties-> Java Build Path ->Source
Add Folder and choose the conf folder.
I checked your code. I think don't need another persistence.xml. Can you try these solutions in play module:
#Test()
public void empty() {
running(fakeApplication(), new Runnable() {
public void run() {
JPA.withTransaction(new play.libs.F.Callback0() {
public void invoke() {
Object o = new Object(someAttrib);
o.save();
assertThat(o).isNotNull();
}
});
}
});
}
Or:
#Before
public void setUpIntegrationTest() {
FakeApplication app = fakeApplication();
start(app);
em = app.getWrappedApplication().plugin(JPAPlugin.class).get().em("default");
JPA.bindForCurrentThread(em);
}
These codes are from this page. I don't test it!
Please modify your code to:
#BeforeClass
public static void setUp() {
FakeApplication app = fakeApplication(inMemoryDatabase());
start(app);
em = app.getWrappedApplication().plugin(JPAPlugin.class).get().em("default");
JPA.bindForCurrentThread(em);
}
Please try it!

EJB Injection failure on deploy

I've got a problem exxh EJB's.
First of all, my setup: I am using GlassFish & JEE6. I have got a REST-Service packaged as a WAR and a bean packaged as an EJB-Jar. They are not inside an EAR.
The EJB should be used from the REST-WAR via #EJB, but when I try to deploy the WAR, GlassFish shows this error:
Error occurred during deployment:
Exception while deploying the app [exx-upload-1.0] : Cannot resolve reference Local ejb-ref name=com.ex.exx.model.FileUpload/ocr,Local 3.x interface =com.ex.exx.api.IOCRService,ejb-link=null,lookup=,mappedName=,jndi-name=,refType=Session. Please see server.log for more details.
(The EJB was deployed before without any erros).
I have no clue why. Here is the EJB Code:
Interface:
#Local
public interface IOCRService {
public String performOCRonImage(BufferedImage input);
}
and Implementation:
#Stateless
#LocalBean
public class OCRScanner implements IOCRService {
private Logger logger = Logger.getLogger(this.getClass().getName());
private final static String NOT_RECOGNIZED = "Can not regocnize text";
/**
* Default constructor.
*/
public OCRScanner() {
logger.log(Level.INFO, "### OCR SCANNER BUILD" + this);
}
public String performOCRonImage(BufferedImage input) {
logger.log(Level.INFO, "### OCR SCANNER CALLED" + this);
}
...
And here is the important part in the WAR:
public class FileUpload {
private final File PROPERTIES_FILE = new File(
"fileUploadProperties.properties");
private final String PARAMETER_NAME = "file";
private final Logger logger = Logger.getLogger(this.getClass().getName());
#EJB
private IOCRService ocr;
public Response uploadFile(...) {
// do some stuff
logger.log(Level.INFO, "### EJB" + ocr.toString())
}
Anny suggestions? I can not find my failure here.
Solved this, by replaceing #Local with #Remote.
This works, however, I am not satisfied as I do not understand why.
Basically, given the specs (eg. explained in the tutorial), an application can only access other application's EJB, if they are decorated with #Remote.
Thus, you have 3 options:
decorate your EJB with #Remote (what you have done),
package both together inside an ear (as they would reside in the
same application then). But if you intent to deploy them in seperate
applications or even seperate servers, use 1.)
use CDI with #Inject, but this will still only discover the EJB if
either in the same application, or decorated as #Remote if not.
HTH,
Alex
You should not use #EJB if the target is not an EJB. I guess this is your case because you are trying to inject into a class in your WAR.
Instead use:
#Inject
private IOCRService ocr;
Basically, #Inject is better in most cases, because:
it is more typesafe,
it supports #Alternatives
it is aware of the scope of the injected object.
Another solution it's to add #Stateless(name=""), this worked form

How do I specify my resourcesXml for Glassfish as a resource itself, and not a local file?

I want to put all my configuration files (arquillian.xml, glassfish-resources.xml,test-persistence.xml) in a library and just reference that when i want to run a test in a project. But it seems the resourceXml only allows for a file-path and not a classpath: variable.
Is there a way to do that?
My configuration is currently based upon the arquillian-persistence-tutorial example project. I actually have no special configuration which is need. Just a in-memory db etc. etc.
I fixed it by extending the Arquillian class, and writing the resource to a local file (in the target folder) before any test.
Now in a domain project i only need to do this in a unit test:
public class MyEntityRepositoryImplTest extends BaseArquillianTest {
#Deployment
public static Archive<?> createDeployment() {
return create().//
addClass(MyEntityRepositoryImpl.class).//
addClass(MyEntityDaoImpl.class).//
addClass(MockSomeRepositoryImpl.class).//
addClass(MyEntityJpa.class);
}
#EJB
private MyEntityRepository myEntityRepository;
#Test
public void mMytest () {
}