溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Jython 2.7.2中提示URI is not hierarchical怎么辦

發(fā)布時間:2021-12-18 15:25:36 來源:億速云 閱讀:780 作者:小新 欄目:大數(shù)據(jù)

這篇文章主要為大家展示了“Jython 2.7.2中提示URI is not hierarchical怎么辦”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“Jython 2.7.2中提示URI is not hierarchical怎么辦”這篇文章吧。

1 .背景

由于需要使用Jython。但是發(fā)現(xiàn)一個詭異的現(xiàn)象IDE使用沒有問題,但是打包jar報錯。

            Properties props = new Properties();
            props.put("python.home","D:\\jython2.7.2");
            props.put("python.path","D:\\jython2.7.2\\Lib\\site-packages");
            props.put("python.console.encoding", "UTF-8"); // Used to prevent: console: Failed to install '': java.nio.charset.UnsupportedCharsetException: cp0.
            props.put("python.security.respectJavaAccessibility", "false"); //don't respect java accessibility, so that we can access protected members on subclasses
            props.put("python.import.site","false");
            //props.put("python.cachedir.skip","true");

            props.put("org.python.netty.noUnsafe","true");

            Properties preprops = System.getProperties();

            PythonInterpreter.initialize(preprops, props, new String[0]);// 此處報異常

            PythonInterpreter pyInterp = new PythonInterpreter();
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.util.PythonInterpreter.initialize(PythonInterpreter.java:63)
        at com.langtutu.ncs.api.robot.core.Test.<init>(Test.java:34)
        at com.langtutu.ncs.api.service.impl.HomestaySchedulingServiceImpl.DownOrderTest(HomestaySchedulingServiceImpl.java:90)
        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.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84)
        at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
        at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

2. 問題查找

使用IDE和遠程調(diào)用分別調(diào)試跟蹤了一下jython,定位到代碼報錯行: Jython 2.7.2中提示URI is not hierarchical怎么辦

  • IDE調(diào)試 發(fā)現(xiàn)url是如下的: jar:file:/D:/maven/apache-maven-3.3.9/repository/org/python/jython/2.7.2/jython-2.7.2.jar!/org/python/core/PrePy.class

  • 遠程調(diào)試

Jython 2.7.2中提示URI is not hierarchical怎么辦

嵌套不能用。

3. 解決方案:

maven打包時候?qū)ython剔除;運行時候加載外部jar包即可。

剔除:

<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<version>2.2.10.RELEASE</version>
				<configuration>
					<layout>ZIP</layout>
					<!--去除在生產(chǎn)環(huán)境中不變的依賴 多個用逗號隔開,-->
					<excludeGroupIds>
						org.python
					</excludeGroupIds>
				</configuration>
			</plugin>
		</plugins>
	</build>

運行:

java -Dloader.path="lib/" -jar .\ncsapi-0.0.1-SNAPSHOT.jar

lib里面就是jar包。此時運行完全正常

以上是“Jython 2.7.2中提示URI is not hierarchical怎么辦”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI