我正在用Jython製作一個Maven項目。在Eclipse中它運行良好,,但是當我運行導出的jar
時,它會發出異常。Jar無法加載包含類文件的文件夾
這是我的目錄裏面src/main/resources
:
src/main/resources:
mylib
file_one.py
file_two.py
pylib
sys.py
sys$py.class
os.py
os$py.class
...
我一直在試圖加載我的文件夾pylib
含有的類文件src/main/resources
這個代碼片段:
public class MyClass {
// ...
public static void init() {
// ...
ClassLoader classLoader = Prompt.class.getClassLoader();
addToPath(path, classLoader.getResource("mylib").getPath());
System.out.println("Found mylib");
addToPath(path, classLoader.getResource("pylib").getPath());
System.out.println("Found pylib");
// ...
}
// ...
}
雖然出口到罐子我得到這個錯誤:
JAR export finished with warnings. See details for additional information.
Problem writing project/src/main/resources/.DS_Store to JAR: duplicate entry: .DS_Store
duplicate entry: .DS_Store
我測試了多次,但該jar只包含文件夾mylib
,不包含類文件。如果我包括pylib
我得到這個錯誤:
java.lang.NullPointerException
at *project*.Prompt.init(Prompt.java:53)
at *project*.Prompt.start(Prompt.java:76)
at *project*.Main.main(Main.java:6)
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:497)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Exception in thread "main" java.lang.reflect.InvocationTargetException
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:497)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Note: I replaced my group id with
*package*
to hide the identity of my project.
有誰知道如何加載的類文件?
Edit:
- Corrected code by adding semicolons.
- Added
println
expression to make clear where the executed jar failed.- Added path information.
- Changed class and project name.
- Added export error.
- Extended runtime error
你想加載java中的python文件嗎? – screenmutt
是的,我使用Jython – Dylan
檢查'pylib'是否在JAR文件中(jar -tvf project.jar) –