include model libraries in appclient jar - glassfish-3

I'm deploying an ear with an EJB onto glassfish 3.1 which I want to call using the appclient script.
The EJB has a method with as parameter a model object which is defined in a separate library.
If I want to use the appclient script I have a Main class with a main method which calls the EJB.
This is also put into a separate jar which is also deployed onto glassfish.
As the model object is located in a separate library I need it in the client jar but also in the EJB.
So I need to reference it somehow in the client jar.
The client jar is a jar (duh) so I cannot add other jars. The Java EE 6 docs say that I should create an ear with the libs but if I do that it doesn't deploy because an ear needs at least an ejb or web module and my client lib has neither.
The solution I found is using the assembly plugin/jar-with-dependencies. This plugin creates a new jar which contains all classes of all dependencies.
This solution works but I'm wondering if this is the way to go or I'm missing something obvious because I cannot imagine this is required. EJB's usually have model objects as parameters so this situation will happen a lot.
So my question is: is there a way to tell glassfish to reference the shared libraries between the app client jar and the ejb jar.

The way I do this is like this:
Separate Maven project with the model. In my case that's a bunch of simple POJOs with JPA and JAX-B annotations, some constants, etc. In Maven, I define this as an OSGi bundle, by specifying <packaging>bundle</packaging>. I call this project MyAppInterface.
Separate Maven projects for other elements that need to deal with the model. In my case, I have one Java EE application with EJBs, Database facade, REST servlet; I have an Integration-Test project which only does tests; a GWT application; etc... In those projects I specify the dependency to the model:
<dependency>
<groupId>com.skalio</groupId>
<artifactId>MyAppInterface</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
When deploying MyAppInterface to Glassfish, I use the following syntax:
asadmin deploy --type osgi --name MyAppInterface /path/to/MyAppInterface-1.0-SNAPSHOT.jar
I understand it that this is placing the model on the classpath of Glassfish, similar to a mysql-connector, only OSGi-style.
I let all these projects be built by a central jenkins CI server, which deploys the artifacts to our internal maven repository. We then add the internal repository in pom.xml of each project. As a result, everyone automatically works with the latest stable MyAppInterface, even if they don't have the code checked out in NetBeans / Eclipse.
Let me know if you need more examples.

Related

Apache Karaf - bundle starts but does nothing?

I'm new to Karaf. I have a jar that has a class App with a method main. When I drop the jar in the The Karaf log service console says the bundle is started but nothing seems to happen. The first thing (the jar) does is a simple database write so I can see if it's running (no log file is generated although one is expected).
The jar depends on lots of other jars. Our sysadmin will not install Maven on the production servers. Where does one put helper jars (like mysql-connector-java-[version].jar)?
Does Karaf use the Manifest file to find the main class? Do I have to implement some special interface or something?
thanks for any help.
As Karaf is a OSGi Container, you should first read some stuff on how to write proper OSGi bundles.
First of all you'll need a Activator that'll start your bundle (just like a main). A Main Class is never interpreted. Yes Karaf, as it is a OSGi container, does "read" the Manifest, but to make sure first it's a proper OSGi bundle second how the resolving should take place by reading Package-Import/-Export.
Regarding the "Packaging" - using lot's of other jar's/bunldes - , you'd either can built a custom Karaf (read the Karaf documentation on how to do this) or create a KAR for your Bundles containing your bundles and a feature.xml (again take a look at the documentation at Karaf)

websphere ejb deployment issue : classnotfound error for other ejb references

I have two ejb jars packaged into a ear. say EJb1.jar adn Ejb2.jar. I am deploying it in Webphere 7.0. Ejb1 is referencing to classes in Ejb2.jar. Unless I specify the Ejb2.jar in Manifest.Mf file of Ejb1.jar, the deployment of EAR file fails.
Throws error that build path is incomplete and that referenced class is not found.
Is there any way I can overcome this ? Through some settings in WebSphere console?
I have too many ejb's in this ear referencing each other.
It makes things really difficult to update manifest file each time we make code changes.
Any ideas ?
If you want to avoid that what you need to do is create and EJB Client Jar which holds the interfaces and put it in the EAR/lib directory.
For example if EJB1.jar got MyBean.java and MyBeanLocal.java you will now split it to 2 jars files:
EJB1.jar (EJB Module) holding MyBean.java and EJB1-Client.jar (Utility Jar) holding MyBeanLocal.java
Then you put EJB1-Client.jar in the EAR file lib directory and EJB2.jar will be able to find the interfaces in its classpath.

External classes/jar in OSGi

My application supports running on many dbms and it requires user to configure dbms connection setting and also provide the jdbc jar file.
Now the application is to be packaged as OSGi bundle. There will be another main jar which lanches OSGi server and starts the application as bundle.
Can you please suggest how can I package the application as bundle and let user provide the jdbc jar file.
Will it require something like the main launcher jar specifying JDBC driver classes as FRAMEWORK_SYSTEMPACKAGES property?
Thanks in advance,
Aman
There are two ways of doing this:
1) Adding the driver.jar to the classpath of the main launcher and, like you say, expose its packages via the framework by specifying that property (or actually you can use the FRAMEWORK_SYSTEMPACKAGES_EXTRA property to just specify additional packages, instead of specifying all of them).
2) Manually wrapping the driver.jar as a bundle, or doing it dynamically at runtime. For example, you could try to wrap bundles that are copied to a certain folder (similar to what Apache Felix File Install does) by using Pax URL or some other tool that can create a bundle out of an ordinary jar file for you (see http://team.ops4j.org/wiki/display/paxurl/Pax+URL).

problem with the injection of an EJB that resides in a jar

I have some problems regarding the EJB injection and I haven't been able to find a solution anywhere.
My situation is the following: I have an EAR file that includes a WAR and several JARs, all listed in the application.xml file. All is working fine for this part.
The problems come out when I try to add what we can call a “plugin system”.
I have a JAR with inside some .xhtml pages, backing beans and EJBs. This JAR, if needed, is inserted inside the EAR in a specific directory (let's call it “plugins”) and is detected from the application at startup.
When the JAR is detected it's path is added to the WAR class loader so all the pages and the backing bean are detected without problems. What is not working is the injection of the EJBs (I tried to use the notation #EJB, #Inject, the lookup...). I can't inject any of the EJBs that is inside the JAR plugin.
My guess is that the application server treats the JAR as a simple library module and doesn't look for any EJB inside it, so they are inside the JAR but not usable from the application.
My question is: there's a way of having this working? I tried to add the JAR in the EAR's MANIFEST.MF but nothing changed...
the application server i'm using is glassfish 3.0. About the application.xml: there's no reference in it about the JARs that are part of what i called "plugin system". This because i detect them when i deploy (or i restart) the application in the application server, so they may or may not be inside the system and i don't really know that before the system is started.
Each plugin JAR is a "collection" of pages and functionalities that can be added or removed from the system dynamically (more less like a real plugin system).
My EAR structure is the following:
MyApp.EAR
META-INF
lib
plugins
plugin1.JAR
app.WAR
logic1.JAR
logic2.JAR
for example: in the application.xml i have the references for app.WAR, logic1.JAR and logic2.JAR (they are always inside the system), at startup the application looks inside the folder "plugins" for any plugin (specific JARs) to be added to the system.
I hope i've been more clear about what i'm trying to do...
It seems that the EJB are not even registered in the JNDI tree of the server. Which application server are you using? You can have a look to this JNDI tree to see if the EJBs are there, but the way to do this depends on the specific server.
How are you declaring the JAR that contains the EJBs in the EAR application.xml?
It should be someting lide this:
<application>
....
<module>
<ejb>nameOfTheJarFile.jar</ejb>
</module>
</application>
The Jar should be in a the "/lib" directory of the EAR.
I hope this helps.

How to make an application client jar file for IBM's launchclient

Hi I'm facing with a bug in old ejb application which is deployed on IBM Websphere 6.1. Previously it ran but now it stopped for some reason which I have to investigate.
I'm trying to get it to run locally on my desktop, and I'm trying to access the session bean with IBM's launchclient application. I pass in the ear as the argument (yes that's IBM specific) and the ears contains both the ejb-jar and the ejb-client.jar (also IBM specific).
Launchclient fails with the message: myear does not contain an Application Client jar file. Which may be true, but it does contain the client-ejb jar file, which I even bothered to address with -CCjar=MyEjbClient.jar.
My question is how can I make an application client jar file?
I cant find much information on the launchclient thing, I do have RAD 7.x or something, but to be honest I want to stay away from it as much as possible and it's getting really frustrating.
regards,
PS someone knows a nice NO IBM job?
It is not sufficient to have an ejb-client-jar, you need an application client JAR. Also, -CCjar can only be specified for an application jar (and it's not necessary if you only have one).
To add an application client JAR to an EAR, you need to:
Create a Java class with a traditional main method.
Package the class in a JAR in the EAR.
Add a Main-Class to the META-INF/MANIFEST.MF in the JAR.
Add a META-INF/application-client.xml file to the JAR.
Add the module to application.xml in the EAR:
<module>
<java>MyClient.jar</java>
</module>

Resources