|
Using Java Version via Jython |
Posted by JC on Apr-07-2014 08:04 |
|
I am attempting to implement
So in a script, I call 'import ChartDirector'. This is the jar, which contains all the related
classes. It is flat, there is no hierarchy, so this import should (and appears to) pull in all
the classes of the package. A good thing.
From there, I did a call to a static function (getVersion()) in the Chart class. This worked
fine and I got a valid return value, etc.
Then I moved on to the XYChart where I ran into my hurdle? I was simply using the
'starter' java project to validate that things were working. When I call "mychart =
ChartDirector.XYChart(200, 300)". When I hit that line, I get an error "TypeError: cannot
create 'ChartDirector.XYChart' instances". Looking at anything involving the instantiation of
an object in python (due to use of jython) it appears I am doing everything correctly.
I know this might be getting more into a language issue than a ChartDirector issue, but
this works in regular Java, so hence I am vexed as to why this error is coming up or even
what it means. I am hoping someone has seen such an issue and can explain what I can
try to resolve this? Thanks in advance!
PS> You might ask "why not use the Python version?" -- simply put, it isn't an option given
the environment I am trying to tie ChartDirector into? |
Re: Using Java Version via Jython |
Posted by Peter Kwan on Apr-08-2014 01:02 |
|
Hi JC,
I have never used Jython before, but I will download Jython and try it myself. I will update
you as soon as possible.
Regards
Peter Kwan |
Re: Using Java Version via Jython |
Posted by Peter Kwan on Apr-08-2014 03:14 |
|
Hi JC,
I have just tried myself. In my case, I have to add the following two jar libraries to the
JYTHONPATH environmental variable:
ChartDirector.jar;j2ee.jar
The j2ee.jar is the Java library from the Enterprise Edition of Java (Java EE). (There are
several editions of Java, like the Micro Edition, Standard Edition and Enterprise Edition.)
The Java EE is required to support JSP applications, and is normally not needed for
command line or desktop applications. As ChartDirector supports JSP as well as command
line and desktop Java applications, it contains methods that accept Java EE classes.
According to the Java standard, these Java EE classes should be loaded the first time the
method is called. If the method is never called, the Java EE classes do not need to load and
j2ee.jar is not needed. That's why standard ChartDirector for Java desktop or command line
applications do not need j2ee.jar.
Apparently, Jython does not comply to that part of the Java standard. It insists on finding
all the Java classes that can potentially be called, before the method is actually called. To
satisfy Jython, we may need to include j2ee.jar so that Jython can find the Java EE class
definitions, even if those classes are never used.
Hope this can help.
Regards
Peter Kwan |
Re: Using Java Version via Jython |
Posted by JC on Apr-08-2014 03:45 |
|
Peter,
Interesting discovery! Can you say what kind of errors you saw when attempting to
instantiate a CD class in Jython before you figured out to add the j2ee.jar to the path?
Curious as I am attempting to confirm that this may be the problem. Note that I am using
Jython in an embedded environment (meaning the Jython interpreter is built into another
software package). That said, I would expect it to have similar issues as you found with
the stand-alone Jython interpreter you were likely testing with? |
Re: Using Java Version via Jython |
Posted by JC on Apr-08-2014 11:30 |
|
Just circling back? I did resolve the issue. The environment I am using constructs its
own classpath and thus does not resolve the J2EE stuff simply by including the javaee.jar
as you did with your example. I had to be much more specific and include the jars that
contained the method bodies: javax.servlet-api.jar and javax.servlet.jsp-api.jar.
I am aware that many posts out there mention that this is bad as it can break certain
portability within a proper J2EE environment, but that is not this case. Nor am I using
JSP. It was really only to satisfy the finicky jython interpreter.
Thanks. |
Re: Using Java Version via Jython |
Posted by Peter Kwan on Apr-08-2014 22:32 |
|
Hi JC,
I am glad to learn that the problem is resolved.
In my case, I am trying to use the standard Jython interactively. As soon as I enter "x =
ChartDirector.XYChart(100, 100)", it displays something like the "Class not resolved error"
pointing to a JSP class, together with a long list of stack trace. I have seen similar errors
before in gcj (the GNU compiler that compiles Java dcode irectly to executable programs),
and the cause is that the gcj insists on resolving all unknown dependency even the method
is not actually called. So I added the JAR file that can contains the JSP class in the
JYTHONPATH environmental variable, and it solves the problem.
Regards
Peter Kwan |
Re: Using Java Version via Jython |
Posted by JC on Apr-08-2014 22:41 |
|
Peter,
Yes, that is what I was getting as well. Glad the errors appear to align between us so that
makes sense now. I appreciate the help, thanks! |
|