javaclass

README.txt

155:c0aa5f64dd9a
2005-01-23 Paul Boddie Added version information.
     1 This file contains some information on the essential concepts and principles
     2 involved in the use of this software.
     3 
     4 Installation
     5 ------------
     6 
     7 Usually, I issue this command first:
     8 
     9   python setup.py build
    10 
    11 The following should, in any case, be sufficient:
    12 
    13   python setup.py install
    14 
    15 I don't think distutils supports uninstall, but the installation just adds the
    16 java and javaclass packages to your site-packages directory and the
    17 runclass.py program to the same bin directory that python resides in.
    18 
    19 Testing
    20 -------
    21 
    22 It should be possible to just run the test.py program and see the results:
    23 
    24   python test.py
    25 
    26 Class Search Paths
    27 ------------------
    28 
    29 Java classes belonging to packages are located using sys.path or PYTHONPATH
    30 in the same way that they would be located using the Java classpath (or
    31 CLASSPATH environment variable). Thus, the rules for locating package
    32 classes are as follows:
    33 
    34  * Classes residing within plain directories which represent a package
    35    hierarchy can be accessed by putting the parent directory of the top of
    36    the package hierarchy on the PYTHONPATH (or sys.path). For example, a
    37    package called mypackage, represented by a directory of the same name at
    38    /home/java/classes/mypackage, would be made accessible by adding the
    39    /home/java/classes directory to the PYTHONPATH.
    40 
    41  * Classes residing within .jar files can be accessed by putting the path to
    42    each .jar file on the PYTHONPATH. For example, a package called
    43    mypackage, represented by a file located at /home/java/lib/mypackage.jar,
    44    would be made accessible by adding the /home/java/lib/mypackage.jar file
    45    to the PYTHONPATH.
    46 
    47 Note that classes not belonging to a package cannot be accessed via such
    48 search paths and are made available using a special module (see "Non-package
    49 Classes" below).
    50 
    51 Importing Classes
    52 -----------------
    53 
    54 In Python, the following statement should be enough to enable Java class
    55 import:
    56 
    57   import javaclass.classhook
    58 
    59 (Other modules reside in the javaclass package, so it is possible to access
    60 them without changing Python's import mechanisms, should such modification be
    61 undesirable or unnecessary.)
    62 
    63 Importing Non-package Classes
    64 -----------------------------
    65 
    66 Classes which do not belong to a package are only accessible when residing
    67 in the current working directory of any program attempting to use them. Such
    68 classes will not be made available automatically, but must be imported from
    69 a special module called __this__.
    70 
    71  * Usage of the "import __this__" statement will cause all classes in the
    72    current directory to be made available within the __this__ module.
    73 
    74  * Usage of the "from __this__ import" construct will cause all classes in
    75    the current directory to be processsed, but only named classes will be
    76    made available in the global namespace unless "*" was specified (which
    77    will, as usual, result in all such classes being made available).
    78 
    79 Running Java Classes
    80 --------------------
    81 
    82 Java classes with a public, static main method can be run directly using the
    83 runclass.py program.
    84 
    85   * Free-standing classes (ie. not belonging to packages) can be run from
    86     the directory in which they reside. For example, suitable classes in the
    87     tests directory would be run as follows:
    88 
    89     cd tests
    90     runclass.py MainTest hello world
    91 
    92   * Classes residing in packages can be run by ensuring that the packages
    93     are registered on the PYTHONPATH (see "Class Search Paths" above). Then,
    94     the testpackage.MainTest class (for example) would be run as follows:
    95 
    96     runclass.py testpackage.MainTest hello world
    97 
    98 Accessing Python Libraries from Java
    99 ------------------------------------
   100 
   101 To wrap Python libraries for use with Java, skeleton classes need to be
   102 compiled corresponding to each of the wrapped classes. Each of the methods
   103 in the skeleton classes can be empty (or return any permissible value) since
   104 the only purpose they serve is to provide the Java compiler with information
   105 about the Python libraries.
   106 
   107   1. Compile the skeleton classes:
   108 
   109      javac examples/Tkinter/tkjava/*.java
   110 
   111   2. Compile the Java classes which use the wrapped Python libraries:
   112 
   113      javac -classpath examples/Tkinter examples/Tkinter/Application.java
   114 
   115   3. Run the wrap.py tool on the directory where the skeleton class files
   116      reside, providing the name of the Python package or module being
   117      wrapped. This converts the directory into a Python package:
   118 
   119      python tools/wrap.py examples/Tkinter/tkjava Tkinter
   120 
   121      Since the Java class files, if left in the processed directory, would be
   122      detected and imported using the special import hook, and since this would
   123      result in two conflicting implementations being imported (with possibly the
   124      non-functional Java classes being made available instead of the generated
   125      wrapper classes), the wrap.py tool removes all processed class files,
   126      leaving only Python source files in the processed directory.
   127 
   128   4. The Java classes which use the wrapped Python libraries can now be
   129      imported and used as described above. The wrapper package (tkjava in
   130      the above example) needs to reside in sys.path or PYTHONPATH, as must
   131      the wrapped library (Tkinter in the above example).
   132 
   133      cd examples/Tkinter
   134      runclass.py Application
   135 
   136 Issues
   137 ------
   138 
   139 Investigate better exception raising. Currently, exceptions have to be
   140 derived from object so that object.__new__ can be used upon them. However,
   141 this seems to prevent them from being raised, and they need to be wrapped
   142 within Exception so that the information can be transmitted to the
   143 exception's handler.
   144 
   145 Consider nicer ways of writing the method names in Python, perhaps using a
   146 function which takes the individual parameter types as arguments.
   147 
   148 Release Procedures
   149 ------------------
   150 
   151 Update the javaclass/__init__.py __version__ attribute.
   152 Update the release notes (see above).
   153 Check the setup.py file and ensure that all package directories are mentioned.
   154 Tag, export.
   155 Rename ClassFile to javaclass (and add the release to the directory name).
   156 Archive, upload.