As far as I am concerned, the best solution is keep your Java development separated from Cocoon. If you Java has no knowledge about or dependency on cocoon, it is much simpler and in my mind also much better to place your Java classes in a separated Jar file and make your cocoon-based application dependent on your Java classes. If you use maven then this is very straightforward to accomplish in cocoon 2.2. The additional advantage is that your can very easy test your Java code without ever running cocoon (e.g. with Netbeans).

To allow my cocoon-based application (or any other application for that matter) to work with my Java code, I typically define a few suitable Facades that are instantiated in Flow using a simple Factory method or with Spring (I prefer the latter approach):

factory:

var facade = Packages.test.SomeFacade.newInstance();  // static method.

or, as Robby pointed out,

importClass(Packages.test.SomeFacade);
var facade = SomeFacade.newInstance();

Spring:

var facade = cocoon.getComponent("test.SomeFacade"); // test.SomeFacade is the bean ID that was defined for the facade
                                                                                
                   // in a Spring configuration file.

Best regards,
André



On 25/01/11 08:17, Robby Pelssers wrote:
importClass(Packages.java.util.ArrayList);

function search() {
     var list = new ArrayList();
     ...
}

Kind regards,
Robby Pelssers


-----Oorspronkelijk bericht-----
Van: Des Magner [mailto:d...@icandriveatractor.com]
Verzonden: zo 23-1-2011 1:25
Aan: users@cocoon.apache.org
Onderwerp: Adding my Java code to flowscript

Hi

I am trying to add some custom code to be called from my flowscript but
with no success. I followed the instructions in the user documentation
to the letter (http://cocoon.apache.org/2.1/userdocs/flow/java.html). I
have added my source directory entry to the component-instance in the
format "file:/path/to/my/source" but it doesn't seem to want to pick up
the code. Say I have the following code in my flowscript:

var resource = new Packages.Test();

with the file Test.java placed in my source dir as specified above, I
consistently get the following error:

org.mozilla.javascript.EvaluatorException: "file:///....js", line ..:
Not a Java class: [JavaPackage Test]

I can get around it by placing the compiled class in the
cocoon/WEB-INF/classes directory but this is not a very elegant solution.

Any help would be greatly appreciated.
Thanks
Des

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@cocoon.apache.org
For additional commands, e-mail: users-h...@cocoon.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@cocoon.apache.org
For additional commands, e-mail: users-h...@cocoon.apache.org


--
Andre H. Juffer              | Phone: +358-8-553 1161
Biocenter Oulu and           | Fax: +358-8-553-1141
Department of Biochemistry   | Email: andre.juf...@oulu.fi
University of Oulu, Finland  | WWW: www.biochem.oulu.fi/Biocomputing/
StruBioCat                   | WWW: www.strubiocat.oulu.fi
NordProt                     | WWW: www.nordprot.org
Triacle Biocomputing         | WWW: www.triacle-bc.com

Reply via email to