Spring portlet ehcache delete cache on portlet undeploy - portlet

I am using Spring portlet ehcache in Liferay environment 6.x
problem is in dev environment if i drop portlet war to deploy folder. After 3-4 attempts it gives me perm gen/ out of memory exception.
Is there a way if my portlet getting redeploy or undeploy remove the cache, i know i can delete the cache by calling getCacheManager().remove("cacheKey"); but when i should to call this any idea how to hook it with portlet instance getting off?
Thanks in advance.

found solution
#PreDestroy
public void cleanup() {
getCacheManager().removeCache(KEY_SERVICE_CACHE);
getCacheManager().removeCache(KEY_SOURCE_CACHE);
}

Related

How to do hot deployment in Jboss5

I have got a maven project.
So when ever there is a changes done in java file, we take a rebuild of the application .
Put our ear file in deploy folder of jboss and restart the Jboss.
This waste our lot of time in restarting jboss again and again .
I heard about hot deployment in Jboss .
Can any one tell how to do in my case .
Hot deploy is enabled by default in JBoss AS 5.
It should start automatically a couple of seconds after you put ear in deploy folder.
Maybe someone had previously disabled hot deployment on your instance.
Then see Turning off JBoss hot deploy service? and do the opposite.
As I understand, u need a class reloading solution, not auto redeployment.
I recently work out a solution with JBoss 4.x. It probably work with JBoss5.x too. In most of time when I change my code, it reflects immediatly and no redeployment in JBoss.
Here is how:
Turn off JBoss hot deploy service, u can google how.
Create a folder named project.war under JBoss deploy folder, it just works like a war file.
User a file sychronize tools(like FreeFileSync) to sychronize your_project_web_root folder to the project.war folder.
The most important part, use spring-loaded. It's easy and no need to change anything in your project.
4.1 Download springloaded.jar
4.2 If u are using eclipse, just add the following code in the VM arguments of the JBoss Run Configuration.
-javaagent:/springloaded-{VERSION}.jar -noverify
That's it. Now u modify/add methods or fields in a class and then sychronize the class file to the project.war folder, JBoss will reload it and the changes reflect immediately. But springloaded still got some limitation, read the FAQ.

How do I use another custom portlet's service layer in Liferay 6.0.6

I have tried two things:
Specified the first portlet as a Required Deployment Context in the second portlet's liferay-plugin-package.properties.
Added the first portlet's portlet service jar to teh second portlet's web app libraries folder.
Neither worked. I still get the ff. exception when I try a dynamic query on the first portlet's service.
java.lang.ClassNotFoundException: com.foo.bar.model.impl.MyPojoImpl
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
at com.liferay.portal.dao.orm.hibernate.DynamicQueryFactoryImpl.getImplClass(DynamicQueryFactoryImpl.java:78)
at com.liferay.portal.dao.orm.hibernate.DynamicQueryFactoryImpl.getImplClass(DynamicQueryFactoryImpl.java:59)
at com.liferay.portal.dao.orm.hibernate.DynamicQueryFactoryImpl.forClass(DynamicQueryFactoryImpl.java:33)
at com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil.forClass(DynamicQueryFactoryUtil.java:23)
Try removing the required deployment context from liferay-plugin-package.properties. After you are done creating service, move the your-service.jar in tomcat/lib/ext folder. Make sure none of your portlet has your-service.jar in its lib folder and then try calling the service.
Regards,
Sandeep
See http://issues.liferay.com/browse/LPS-13073. Either upgrade plugin SDK to later than 6.0.5 or follow patching instructions in second comment.

Emply EJB and Servlet

After reading about it for so long, I now have chance to get my hand dirty with EJB. I use Glassfish+Eclipse 3.7 on Ubuntu.
I first created an EJB that just returns a greeting message. Then I create the application client to access this EJB using InitialContext. This works exactly like expected.
Then, I created a servlet to access to that EJB. Neither access with #EJB nor InitialContext works.
When I use #EJB, the 404 page appear with this description: "The requested resource () is not available."
When I use InitialContent, an ClassNotFoundException is thrown. Apparently, the class loader of the servlet cannot access to the EJB class. I tried to add EJB jar file to the servlet's lib folder and I got the error message that the JNDI name already exists. Apparently, Glass Fish tries publish the EJB in the Servlet's lib folder too.
The only way to get this to work is to publish the EJB with the servlet. This way, both I can get the servlet and a stand-alone application to access to that EJB. The problem is that I need to always employ the servlet with the EJB which is not desirable since my client may not want to use web front end.
Anyway, my question is what is appropriate way to have the servlet access to the EJB employed outside its class loader without repeatedly publishing the EJB.
P.S. It is also possible that the problem might be the way Eclipse configure and employ those components.
Thank a lot for any helps.
Perhaps you need to treat the EJB component as if it were remote. And maybe it really is since you don't give a lot of detail on how you are deploying. Try the directions at http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html#nonJavaEEwebcontainerRemoteEJB.
A few pointers:
you may need to put the webapp and the ejb-jar in an .ear (enterprise application) and deploy it to glassfish
you may need the remote interfaces on the classpath of the webapp (if they are not available at runtime, but they were at compile time, you can't expect it to work)
NetBeans is generally better with enterprise stuff and wizards for creating and deploying applications. Give it a try.
After try out a while, I found that I can do by referring it as "/". This even works with injection.

Websphere 7 EntityManagerFactory creation problem

I'm working on a maven project which uses seam 2.2.0, hibernate 3.5.0-CR-2 as JPA provider, DB2 as database server and Websphere 7 as application server. Now I'm facing de following problem:
In my EJBs that are seen also as SEAM components I want to use the EntityManager from EJB container (#PersistenceContext private EntityManager em) not Seam's EntityManager (#In private EntityManager em). But this is the problem, I cannot obtain an EntityManager using #PersistenceContext.
On server logs it sais that it cannot create an EntityManagerFactory and gets a ClassCastException:
java.lang.ClassCastException: org.hibernate.ejb.HibernatePersistence incompatible with javax.persistence.spi.PersistenceProvider
After a lot of debugging and searching on forums I'm assuming that the problem is that Websphere doesn't use the Hibernate JPA provider.
Has anyone faced this problem and has a solution? I configured already WAS class loader order for my application to load the classes with the application class loader first and I\ve packed all necessary jars in application ear as written in: WAS InfoCenter: Features for EJB 3.0 development . If necessary I'll post my persistence.xml, components.xml files and stack trace.
I've found this problem discussed also here:
Websphere EntityManagerFactory creation problem
Hibernate 3.3 fail to create entity manager factory in Websphere 7.0. Please help
Any hint will be useful.
Thanks in advance!
Mihaela
I suspect that you've included the JPA API jar in your EAR. When using "parent last" (also known as "load classes with application class loader first"), your application is loading a second copy of the javax.persistence.spi.PersistenceProvider class, which is incompatible with the copy included in WAS. You need to either remove those classes from your EAR or change back to "parent first" delegation mode.

JBoss AS 4.2.3 Hot deploy Exploded files

I have an issue hot deploying on JBoss Application Server 4.2.3.GA. The server does not redeploy the application when i update the web.xml file. Is it that only classes changed will make the server to redploy the application? If this is the case how do I redeploy non-class files?
Please advice.
Thanks, Saquib
JBoss redeploys the web application when it detects a change to the web.xml.
Make sure that whatever you are using to modify this makes a change to the timestamp on the file. So
touch web.xml
should be the charm for a redeploy
If your application is expanded from an EAR, being the WAR a part of it, try updating the META-INF/application.xml file.