[Javassist user questions] - javassist.CannotCompileException: by java.lang.LinkageError:
by arsami
Hi,
I am trying to change a class on-the-fly with this small program:
| Hello h = new Hello();
| h.say();
| ClassPool cp = new ClassPool(true);
| CtClass cc = cp.get("com.blabla.test.Hello");
| CtMethod m = cc.getDeclaredMethod("say");
| m.insertBefore("{ System.out.println(\"Hello.say():\"); }");
| Class c = cc.toClass();
| h = (Hello)c.newInstance();
| h.say();
and I get the following exception:
| javassist.CannotCompileException: by java.lang.LinkageError: duplicate class definition:
| at javassist.ClassPool.toClass(ClassPool.java:953)
| at javassist.ClassPool.toClass(ClassPool.java:896)
| at javassist.ClassPool.toClass(ClassPool.java:854)
| at javassist.CtClass.toClass(CtClass.java:1053)
| at com.blabla.test.PlainTester.testMethodInjection(PlainTester.java:32)
|
| Caused by: java.lang.LinkageError: duplicate class definition: com/blabla/test/Hello
| at java.lang.ClassLoader.defineClass1(Native Method)
| at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
| at java.lang.ClassLoader.defineClass(ClassLoader.java:465)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at javassist.ClassPool.toClass2(ClassPool.java:965)
| at javassist.ClassPool.toClass(ClassPool.java:947)
| ... 6 more
Of course, if I don't use the Hello class before injecting that method, it works fine. All the sample programs that I found on the net are showing a method injection without any prior use. However, my requirement is that, I have to be able to change a class while the system is running.
Is there any way that we can do that?
Your help is greatly appreciated...
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4127954#4127954
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4127954
18 years, 2 months
[JBoss Seam] - Re: Migrating Seam application from Windows to Redhat
by supernovasoftware.com
Thanks Norman. That is what I figured. If anyone else has tips, please let me know.
This is why I hired the consultant fast track things like:
1. Setting multiple JBAS instances to start of on separte IP addresses
2. Make these services start after PostgreSQL
3. General security and management concerns.
4. Make me a kickstart install disk.
Where would be the best place to ask the following licensing questions?
1. Can I include JBoss LGPL products on the kickstart that will install the OS?
2. Can I include my closed source application based on JBoss LGPL products on my kickstart disk?
This kickstart disk is mainly for disaster recovery and will not be distributed as a generic installer for the application.
I will however install fresh copy of Linux. Run a script to set up the database and JBAS and deploy my application.
I can put the application setup on a separate disk if necessary, but would rather not.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4127951#4127951
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4127951
18 years, 2 months
[JBoss Seam] - Re: How do I fetch the HTML source of a page programatically
by JakeC
OK, I think I'm getting much closer. MailComponent.encode() has the process down, but from within a UIComponent, which renders differently. However, the info from Monkey shows how to render from outside a UIComponent, and org.jboss.seam.ui.facelet.FaceletsRenderer showed how to create a ResponseWriter (the one from FacesContext is null). Here is what I have so far:
try {
| FacesContext facesContext = FacesContext.getCurrentInstance();
| ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
| UIViewRoot viewRoot = viewHandler.restoreView(facesContext, "/myDir/myPage.xhtml");
| if(viewRoot == null) {
| log.info("restoreView returned null, calling createView");
| viewRoot = viewHandler.createView(facesContext, "/myDir/myPage.xhtml");
| }
| StringWriter stringWriter = new StringWriter();
| ResponseWriter originalResponseWriter = facesContext.getResponseWriter();
| if(originalResponseWriter == null) {
| log.info("responseWriter is null, creating new one");
| facesContext.setResponseWriter(facesContext.getRenderKit().createResponseWriter(stringWriter, null, null));
| } else {
| ResponseWriter cachingResponseWriter = originalResponseWriter.cloneWithWriter(stringWriter);
| facesContext.setResponseWriter(cachingResponseWriter);
| }
| viewHandler.renderView(facesContext, viewRoot);
| if(originalResponseWriter != null)
| facesContext.setResponseWriter(originalResponseWriter);
| String output = stringWriter.getBuffer().toString();
| log.info("Rendered data: {0}", output);
| } catch (Throwable t) {
| log.error("Error rendering: {0}", t, t.getMessage());
| }
Here is the output I got:
restoreView returned null, calling createView
| responseWriter is null, creating new one
| Rendered data:
The call to restoreView() returns null, so I call createView(). I suspect that this may be my problem. I'm getting nothing rendered because I am creating a new view, not restoring my existing one. The viewId I'm using is "/myDir/myPage.xhtml", like I would refer to it in in pages.xml. Is this incorrect? If so, what should I use for viewId?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4127949#4127949
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4127949
18 years, 2 months