Closed MichaelErichsen closed 2 years ago
Jython is an implementation of the high-level, dynamic, object-oriented language Python seamlessly integrated with the Java platform. The predecessor to Jython, JPython, is certified as 100% Pure Java. Jython is freely available for both commercial and non-commercial use and is distributed with source code. Jython is complementary to Java and is especially suited for the following tasks:
Embedded scripting - Java programmers can add the Jython libraries to their system to allow end users to write simple or complicated scripts that add functionality to the application.
Interactive experimentation - Jython provides an interactive interpreter that can be used to interact with Java packages or with running Java applications. This allows programmers to experiment and debug any Java system using Jython.
Rapid application development - Python programs are typically 2-10X shorter than the equivalent Java program. This translates directly to increased programmer productivity. The seamless interaction between Python and Java allows developers to freely mix the two languages both during development and in shipping products.
How to Connect Python to H2: https://stackoverflow.com/questions/41493117/connect-python-to-h2
It is possible that this can be used: http://www.pydev.org/index.html
Installed Pydev plugin from Eclipse Marketplace
Jython installed from http://www.jython.org/archive/22/installation.html
Main documentation: http://www.jython.org/jythonbook/en/1.0/index.html
Newer Jython installation: http://www.jython.org/downloads.html
Added jython.jar from the Jython installation directory to the "Other jars" directory, which is part of the Plug-in Target Platform
Added an access rule for org/python/** in Java Build Path, Libraries, Plug-in Dependencies
Created a Java Plug-in project for testing. PyDev, Set as PyDev project. Configured Jython in the project properties. Added both Java code and Jythin code in the src folder of the project
from org.jython.book.interfaces import BuildingType
class Building(BuildingType): def init(self, name, address, id): self.name = name self.address = address self.id = id
def getBuildingName(self):
return self.name
def getBuildingAddress(self):
return self.address
def getBuldingId(self):
return self.id
/*
import org.jython.book.interfaces.BuildingType; import org.python.core.PyObject; import org.python.core.PyString; import org.python.util.PythonInterpreter;
public class BuildingFactory {
private PyObject buildingClass;
/**
* Create a new PythonInterpreter object, then use it to
* execute some python code. In this case, we want to
* import the python module that we will coerce.
*
* Once the module is imported than we obtain a reference to
* it and assign the reference to a Java variable
*/
public BuildingFactory() {
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec("from Building import Building");
buildingClass = interpreter.get("Building");
}
/**
* The create method is responsible for performing the actual
* coercion of the referenced python module into Java bytecode
*/
public BuildingType create (String name, String location, String id) {
PyObject buildingObject = buildingClass.__call__(new PyString(name),
new PyString(location),
new PyString(id));
return (BuildingType)buildingObject.__tojava__(BuildingType.class);
}
}
// Java interface for a building object package org.jython.book.interfaces;
public interface BuildingType {
public String getBuildingName();
public String getBuildingAddress();
public String getBuildingId();
}
package org.jython.book;
import org.jython.book.util.BuildingFactory; import org.jython.book.interfaces.BuildingType;
public class Main {
private static void print(BuildingType building) {
System.out.println("Building Info: " +
building.getBuildingId() + " " +
building.getBuildingName() + " " +
building.getBuildingAddress());
}
/**
* Create three building objects by calling the create() method of
* the factory.
*/
public static void main(String[] args) {
BuildingFactory factory = new BuildingFactory();
print(factory.create("BUILDING-A", "100 WEST MAIN", "1"));
print(factory.create("BUILDING-B", "110 WEST MAIN", "2"));
print(factory.create("BUILDING-C", "120 WEST MAIN", "3"));
}
}
Run main as Java Application:
Building Info: null BUILDING-A 100 WEST MAIN Building Info: null BUILDING-B 110 WEST MAIN Building Info: null BUILDING-C 120 WEST MAIN
The method and code is taken from http://www.jython.org/jythonbook/en/1.0/JythonAndJavaIntegration.html#using-jython-within-java-applications
Now needing to find a way to embed this in HRE v0.1
What does that mean? thanks, Lynn
On Fri, Jul 20, 2018 at 1:15 PM Michael Erichsen notifications@github.com wrote:
Assigned #42 https://github.com/History-Research-Environment/HRE--History-Research-Environment/issues/42 to @LynnAnnMcL https://github.com/LynnAnnMcL.
— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/History-Research-Environment/HRE--History-Research-Environment/issues/42#event-1745287244, or mute the thread https://github.com/notifications/unsubscribe-auth/Anhp-C-e7frpDZBvSxStpkrh36bxVwWKks5uIhAzgaJpZM4VIMUh .
From @MichaelErichsen on October 23, 2017 10:46
I would also be very interested within the Eclipse environment to be able to use Jython as a scripting language for report composition.
I would like to see this as a way where report scripts can be modified by more expert users to achieve bespoke reports.
Hence the concept would be that Jython would access the HRE Java components to sequence a report.
I understand that Jython scripts can also contain their own options selection GUI via Swing components initiated from the Jython script.
I don't want HRE to be limited to the rigid canned reports that we have in TMG.
(Robin)
Copied from original issue: MichaelErichsen/HRE--History-Research-Environment#31