From: DOUTCH GARETH-G. <Gar...@mo...> - 2007-02-22 15:14:30
|
I am trying to compile with external jar file as a dependency, but when I run the created Jar file, I get ImportErrors. =20 (This example uses the Mig layout manager http://www.miglayout.com <http://www.miglayout.com/> ) Consider the following short swing UI demos using jython.bat that has the MigLayout.jar on it's classpath: =20 ------------ jython.bat ------------ set MYCP=3DC:\Jython\swingmiglayout15.jar; set MYCP=3D%CLASSPATH%;%MYCP% =20 "C:\Program Files\Java\jre1.6.0\bin\java.exe" = -Dpython.home=3D"C:\jython" -classpath "C:\jython.jar;%MYCP%" org.python.util.jython %ARGS% ------------- =20 The following demo with no external dependencies: =20 ----------- nodep.py ----------- import javax.swing import java.awt =20 def Exit(event): import java.lang java.lang.System.exit(0) =20 def DoStuff(event): print "stuff" =20 class DemoFrame(javax.swing.JFrame): def __init__(self, title=3D"Demo Frame"): """@sig public DemoFrame(String title)""" self.title =3D title self.windowClosing =3D Exit doStuffButon =3D javax.swing.JButton("Do Stuff", actionPerformed=3DDoStuff) self.setLayout(java.awt.BorderLayout()) self.add(doStuffButon, java.awt.BorderLayout.CENTER) self.pack() self.setLocationRelativeTo(None) =20 =20 if __name__ =3D=3D "__main__": DemoFrame().show() =20 ----------- =20 Run with C:\Jython> jython demonodep.py brings up the little frame with the button that prints "stuff" when it is clicked. Compile it with the args: C:\Jython> jythonc.bat --core --jar C:\Jython\nodep.jar C:\jython\nodep.py and running the jar like so: > java -jar C:\Jython\nodep.jar Gives exactly the same results: =20 Now, the following demo with an external dependancy: =20 ----------------- dep.py ----------------- =20 import javax.swing import java.awt =20 def Exit(event): import java.lang java.lang.System.exit(0) =20 def DoStuff(event): print "stuff" =20 import net.miginfocom.swing.MigLayout class DemoFrame(javax.swing.JFrame): def __init__(self, title=3D"Demo Frame"): """@sig public DemoFrame(String title)""" self.title =3D title self.windowClosing =3D Exit doStuffButon =3D javax.swing.JButton("Do Stuff", actionPerformed=3DDoStuff) self.setLayout(net.miginfocom.swing.MigLayout()) self.add(doStuffButon) self.pack() self.setLocationRelativeTo(None) =20 if __name__ =3D=3D "__main__": DemoFrame().show() =20 ---------------- =20 Compiling it however, results in ImportErrors whenever the Jar is run. (Maybe it's because I don't know how to use JythonC properly?) =20 I have tried compiling with all of the following commands: =20 C:\Jython> jythonc --core --jar C:\Jython\dep.jar C:\Jython\dep.py C:\Jython> jythonc --addpackages net.miginfocom.swing --core --jar C:\Jython\dep.jar C:\Jython\dep.py C:\Jython> jythonc --addpackages net.miginfocom.swing.MigLayout --core --jar C:\Jython\dep.jar C:\Jython\dep.py =20 And I see the following error each time I run > java -jar C:\Jython\dep.jar ImportError: No module named MigLayout =20 What am I missing? =20 Gareth =20 =20 =20 =20 =20 |
From: Diez B. R. <de...@we...> - 2007-02-23 13:35:35
|
> And I see the following error each time I run > > > java -jar C:\Jython\dep.jar > > ImportError: No module named MigLayout > > What am I missing? > I presume you're missing the depending jar on the classpath. Obviously, the compilation itself went well, the import statement is executed. But how do you expect the JVM to find some arbitrary jar referred to implicitely by an import statement? Something like java -cp swingmiglayout15.jar -jar C:\Jython\dep.jar should work I guess. Diez |
From: DOUTCH GARETH-G. <Gar...@mo...> - 2007-02-23 13:53:24
|
Thanks Diez, I read that when you use the JythonC options --jar or --deep, that it compiles "all dependencies" into the single jar file. Meaning I thought my external jar would have been included in the jar that I have just built! I guess this is something to add to the tutorial so it's clear to noobs like myself who have no Java background. When I have a spare 5 mins, I'll write this on my blog. "Jython compiling for dummies" or something! I'll let you guys know, maybe it will help for tutorial stuff. -----Original Message----- From: de...@we... [mailto:de...@we...]=20 Sent: 23 February 2007 13:35 To: jyt...@li... Cc: DOUTCH GARETH-GDO003 Subject: Re: [Jython-users] JythonC and external packages? > And I see the following error each time I run > > > java -jar C:\Jython\dep.jar > > ImportError: No module named MigLayout > > What am I missing? > I presume you're missing the depending jar on the classpath. Obviously, the compilation itself went well, the import statement is executed. But how do you expect the JVM to find some arbitrary jar referred to implicitely by an import statement? Something like=20 java -cp swingmiglayout15.jar -jar C:\Jython\dep.jar should work I guess. Diez |
From: Diez B. R. <de...@we...> - 2007-02-23 13:56:59
|
On Friday 23 February 2007 14:53, DOUTCH GARETH-GDO003 wrote: > Thanks Diez, > > I read that when you use the JythonC options --jar or --deep, that it > compiles "all dependencies" into the single jar file. Meaning I thought > my external jar would have been included in the jar that I have just > built! I guess this is something to add to the tutorial so it's clear to > noobs like myself who have no Java background. > > When I have a spare 5 mins, I'll write this on my blog. "Jython > compiling for dummies" or something! I'll let you guys know, maybe it > will help for tutorial stuff. Well, it says """ --jar jarfile -j jarfile -jar jarfile Specifies a .jar file to create and put the results of the freeze into. Implies the --deep option. """ """ --deep -d -deep Compile all Python dependencies of the module. This is used for creating applets. """ That is Python-dependencies - not java-dependencies. Diez |
From: DOUTCH GARETH-G. <Gar...@mo...> - 2007-02-23 15:20:53
|
Next question: Supposing I would like to put my code and the external packages into a single file for distribution, would JythonC enable me to do that (and how?) Cheers, Gareth=20 -----Original Message----- From: de...@we... [mailto:de...@we...]=20 Sent: 23 February 2007 13:57 To: jyt...@li... Cc: DOUTCH GARETH-GDO003 Subject: Re: [Jython-users] JythonC and external packages? On Friday 23 February 2007 14:53, DOUTCH GARETH-GDO003 wrote: > Thanks Diez, > > I read that when you use the JythonC options --jar or --deep, that it=20 > compiles "all dependencies" into the single jar file. Meaning I=20 > thought my external jar would have been included in the jar that I=20 > have just built! I guess this is something to add to the tutorial so=20 > it's clear to noobs like myself who have no Java background. > > When I have a spare 5 mins, I'll write this on my blog. "Jython=20 > compiling for dummies" or something! I'll let you guys know, maybe it=20 > will help for tutorial stuff. Well, it says """ --jar jarfile -j jarfile=20 -jar jarfile Specifies a .jar file to create and put the results of the=20 freeze into. Implies the --deep option.=20 """ """ --deep -d=20 -deep Compile all Python dependencies of the module. This is used for=20 creating applets. """ That is Python-dependencies - not java-dependencies. Diez |
From: Diez B. R. <de...@we...> - 2007-02-23 15:49:29
|
On Friday 23 February 2007 16:20, DOUTCH GARETH-GDO003 wrote: > Next question: > > Supposing I would like to put my code and the external packages into a > single file for distribution, would JythonC enable me to do that (and > how?) I'm not sure if and how that works - I presume there are ways, but in the end this is a Java-question. If you can figure out how to create application bundles for java, you can do that with your jythonc-code as well. Yet I don't think that this is a feature of jythonc - otherwise it would be mentioned. Diez |