On 01/25/2011 06:57 PM, Des Magner wrote:
Hi André

That is more or less what I was trying to achieve, ie. write Java code that
can be used in my flowscript but for this Java code to be completely
independent of cocoon. From reading the documentation I was given
to understand that this code could be compiled on the fly which would
of course speed up development time (See the documentation link I referenced
in the original post). I have never had any problem using standard Java
classes, such as ArrayList, etc. in flowscript, the problem is accessing
classes that I have written. So as far as I can see there are three options
outlined below, the third one being the only one I have been able to
successfully achieve.

Option 1: Have your code compiled on the fly, specifiying in cocoon.xconf a
classpath as to where it should look for source code. I cannot get this to
work and this was why I posted the message in the first place. In more
detail this is what I do:

Add the following to cocoon.xconf:

<flow-interpreters default="javascript" logger="flow">
   <component-instance
class="org.apache.cocoon.components.flow.javascript.fom.
FOM_JavaScriptInterpreter"
name="javascript">

<load-on-startup>resource://org/apache/cocoon/components/flow/
javascript/fom/fom_system.js</load-on-startup>
     <reload-scripts>true</reload-scripts>
     <check-time>4000</check-time>
     <classpath>file:/path/to/my/java/src</classpath>
   </component-instance>
</flow-interpreters>

Javascript in my flowscript:

var resource = new Packages.mypackage.xyz.MyClass();

Throws the following exception:

org.mozilla.javascript.EcmaError: TypeError:
[JavaPackage mypackage.xyx.MyClass] is not a function,
it is org.mozilla.javascript.NativeJavaPackage.


Option 2: Complile my code to the my application's WEB-INF/classes
directory (or alternatively place it in a jar file in the application's
WEB-INF/lib directory. This I also tried but to no avail.

Option 3: Place the compiled classes in the cocoon's own classes folder.
When I do this I can indeed access my Java classes from flowscript.
But this for me is the least desireable solution as it requires me to
mix my own class files with cocoons class files which I don't consider
elegant nor correct. And also, cocoon would need to be restarted
everytime I make a modication to my Java classes.

I have only experience with option 3, I cannot say so much about the other options. If you use cocoon 2.2, the dependency goes in the pom.xml. With earlier versions, one can write an ant script to ensure that the jar file (say test.jar) is deposited in WEB-INF/lib. This all certainly works very well and, to me (not to you apparently), is the simplest and easiest way.

It is correct that you would need to restart cocoon after a modification to your classes. On the other hand, if you have designed your classes well, and tested well, you can bring this down to a minimum. For a new project, I never start with cocoon, but work on a proper design and implementation of the domain and rules, and, if needed, basic infrastructure (database, etc) as well. When start to use cocoon, I am rather certain that every already works well (classes in the jar, that is).

BTW which version of cocoon are you using?

I also wonder about your design. You say you are required to mix your classes with cocoon classes. Why is that necessary? I may have misunderstood you.


Regards
Des


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



--
Andre H. Juffer              | Phone: +358-8-553 1161
Biocenter Oulu and           | Fax: +358-8-553-1141
Department of Biochemistry   | Email: [email protected]
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

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to