Tag Archives: Jython

Using java to call Jython, the error URI is not hierarchical

IllegalArgumentException: URI is not hierarchical] with root cause
java.lang.IllegalArgumentException: URI is not hierarchical
	at java.io.File.<init>(File.java:418)
	at org.python.core.PrePy.getJarFileNameFromURL(PrePy.java:427)
	at org.python.core.PrePy._getJarFileName(PrePy.java:362)
	at org.python.core.PrePy.getJarFileName(PrePy.java:345)
	at org.python.core.PySystemState.doInitialize(PySystemState.java:1195)
	at org.python.core.PySystemState.initialize(PySystemState.java:1130)
	at org.python.core.PySystemState.initialize(PySystemState.java:1085)
	at org.python.core.PySystemState.initialize(PySystemState.java:1080)
	at org.python.core.PySystemState.initialize(PySystemState.java:1075)
	at org.python.core.PySystemState.initialize(PySystemState.java:1070)
	at org.python.core.ThreadStateMapping.getThreadState(ThreadStateMapping.java:56)
	at org.python.core.Py.getThreadState(Py.java:1741)
	at org.python.core.Py.getThreadState(Py.java:1737)
	at org.python.core.Py.getSystemState(Py.java:1757)
	at org.python.util.PythonInterpreter.<init>(PythonInterpreter.java:100)
	at org.python.util.PythonInterpreter.<init>(PythonInterpreter.java:93)
	at org.python.util.PythonInterpreter.<init>(PythonInterpreter.java:70)
	at com.example.kimnara.controller.KafkaProducer.invokPy(KafkaProducer.java:138)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792)

Remote breakpoint discovery through idea
the URL found is as follows: jar: File:/D:/Maven/apache-maven-3.3.9/repository/org/python/jython/2.7.2/jython-2.7.2.jar/ Org/Python/core/prep.class
nesting cannot be used
solution: Jython will be eliminated when Maven is packaged; Just load the external jar package at runtime.

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <layout>ZIP</layout>
                    <excludeGroupIds>
                        org.python
                    </excludeGroupIds>
                </configuration>
            </plugin>
        </plugins>
    </build>


java -Dloader.path=“lib/” -jar kimnara-0.0.1-SNAPSHOT.jar
The jar package placed inside the lib

Jython installation

Jython installation is a bit bumpy
Jython installation small bumpy background software configuration installation process encountered problems in the last episode

Jython installation is a bit bumpy
background
Since Jython is required to use MonkeyRunner, let’s take a look at the bumps in the Android process.
Software configuration
Operating system: Windows 7 64-bit
Java version: 1.8.3
Python version: 2.7.8
The installation process
To get started, go to Jython’s official website and download the latest version of Jython, which comes in a.JAR.
in CMD directly with java-jar + jar command to install
Problems encountered
After using the latest version of Jython installation, an Error was reported in CMD, indicating Error loading python27.dll (Error code 14001). The search engine searched and found the reason on stackoverflow. Jython2.7.1 does not support Windows 7. You can only download version 2.7.0 or lower. You found 2.7.0 here and downloaded the JAR package.
is installed directly in CMD with the java-jar + jar command, as before.
error was reported again this time. The error was reported as follows:

Error: Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion'
has value '1.8', but '1.7' is required.
Error: could not find java.dll
Error: Could not find Java SE Runtime Environment.

This does not need the search engine to know is Java is too high, alas, have no way, have to change the environment variable of the system Java in the computer to 1.7.
thought this would be fine,
did not expect, after changing the Java version to reinstall the same prompt, I wonder. I read the Java version in CMD with java-version, 1.7. Why not?Have no way, have to turn to search engine again. [results] (https://stackoverflow.com/questions/29697543/registry-key-error-java-version-has-value-1-8-but-1-7-is-required) found the answer in this: the reason is that in the system path, Windows\System32 or Windows\SysWOW64 there are java.exe, javaw.exe, javaws.exe0 these files are still 1.8.3.
in this case, I guess the cache, although the environment variable has changed, but the path has not been changed.
The last
Finally, it is installed successfully. To check whether it is installed, you need to configure the environment variable. jython.exe· the path is in the /bin file of the installation path. After configuring it, just like Python, enter jython ‘in CMD directly and see if it enters jython.
episode
When the installation failed at the beginning, I went to the official installation guide on the official website. Jar –help java-jar jythn-installer -2.7.1.jar –help
I found that -help or -help is very useful, sometimes do not know what command, you can type this parameter in the back, see if it is useful. “Hee hee”

usage:
       java -jar jython-installer-2.7.0.jar [-c | -s | -A] [-d dir] [-t type] [-i
       part(s)] [-e part(s)] [-v] [-h | -?]

No option at all will start the interactive GUI installer, except:
Options respected in GUI mode are 'directory', which serve as default values
in the wizard.
In non-GUI mode the following options are available:
 -c,--console             console based installation (user interaction)
                          any other options will be ignored (except 'verbose')
 -s,--silent              silent installation (without user interaction)
 -A,--autotest            automatic stress tests for the installer
                          most of the other options are ignored
                          allowed additional options: 'verbose
 -d,--directory <dir>     target directory to install to
                          (required in silent mode,
                          used as default in GUI mode)
 -t,--type <type>         installation type
                          one of the following types is possible
                          (see also include/exclude parts):
                          - all: everything (including src)
                          - standard: core, mod, demo, doc, ensurepip
                          standard is the default
                          - minimum: core
                          - standalone: install a single, executable .jar,
                          containing all the modules
 -i,--include <part(s)>   finer control over parts to install
                          more than one of the following is possible:
                          - mod: library modules
                          - demo: demos and examples
                          - doc: documentation
                          - src: java source code
                          - ensurepip: install pip and setuptools
 -e,--exclude <part(s)>   finer control over parts not to install
                          more than one of the following is possible:
                          - mod: library modules
                          - demo: demos and examples
                          - doc: documentation
                          - src: java source code
                          - ensurepip: install pip and setuptools
                          (excludes override includes)
 -v,--verbose             print more output during the installation
                          (also valid in GUI and autotest mode)
 -h,--help                print this help (overrides any other options)
 -?                      print this help (overrides any other options)

example of a GUI installation:
        java -jar jython-installer-2.7.0.jar

example of a console installation:
        java -jar jython-installer-2.7.0.jar -c

example of a silent installation:
        java -jar jython-installer-2.7.0.jar -s -d targetDirectory

examples of a silent installation with more options:
        java -jar jython-installer-2.7.0.jar -s -d targetDirectory -t minimum -i src
        java -jar jython-installer-2.7.0.jar -s -d targetDirectory -t standard -e demo doc -i src

example of an autotest installation into temporary directories:
        java -jar jython-installer-2.7.0.jar -A
        (uses java.awt.Robot; make sure you do NOT touch mouse NOR keyboard
         after hitting enter/return!)

In the end, I deliberately installed it without a graphical interface, using -C to install it with the console, and found that there were more options to choose than the graphical interface, so I won’t expand it here.
be interested in yourself to try.