I'm making a Maven project with Jython. In Eclipse it runs fine, but when I run the exported jar
it trows an exception.
This are my directories inside src/main/resources
:
src/main/resources:
mylib
file_one.py
file_two.py
pylib
sys.py
sys$py.class
os.py
os$py.class
...
I've been trying to load my folder pylib
containing class files in src/main/resources
with this snippet of code:
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");
// ...
}
// ...
}
While exporting to jar I got this error:
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
I tested it multiple times, but the jar only included the folder mylib
that didn't contain class files. If I included pylib
I got this error:
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.
Does anyone know how to load the class files?
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