Lisp filepath issues when running application directly from jar file
Hi, I was working on an application, that loads a few lisp files using lisp command (load "fullfilepath.lisp") from java using ABCL. This file in turn loads the other lisp files located in same folder hierarchy, and then i call lisp functions (defined in these files) from java and everything works perfect as long as I run the application from Netbeans. Close to deployment, I tested the application by running it from jar file, I found that there are issues with filepaths, as the files are not a part of file-system, and hence not accessible using a file-path. Does anyone has any idea how to fix this issue ? I tried many things, like URL url = LispConnector.class.getResource("/Aima/aima/quicklisp/setup.lisp");String path = url.getFile();File f = new File(path); path = f.getAbsolutePath(); path = path.replace("\\", "/"); which returns [image: enter image description here] But which is wrong as this is not a valid file path and does not exists so lisp : (load "filepath") fails here. When I use the code String path = url.toURI();File = new File(path); path = path.getAbsolutePath(); Again it works fine while running from netbeans, but shows error "URI is not hierarchical" error while running the jar file. Has anyone encountered this issue, please help. -- Hamda Binte Ajmal NUIG, Ireland
On Aug 14, 2015, at 12:20, Hamda Binte Ajmal <hamda.binte.ajmal@gmail.com> wrote:
Hi, I was working on an application, that loads a few lisp files using lisp command (load "fullfilepath.lisp") from java using ABCL. This file in turn loads the other lisp files located in same folder hierarchy, and then i call lisp functions (defined in these files) from java and everything works perfect as long as I run the application from Netbeans. Close to deployment, I tested the application by running it from jar file, I found that there are issues with filepaths, as the files are not a part of file-system, and hence not accessible using a file-path. Does anyone has any idea how to fix this issue ?
ABCL has [extended the semantics of Lisp PATHNAME objects to be able to refer to files within jar files][1]. [1]: http://abcl.org/trac/browser/trunk/abcl/doc/design/pathnames/jar-pathnames.m... If you know the absolute path of the jar file locally, you may specify a file within via something that looks like: “jar:file:/absolute/path/to/file.jar!/path/within/jar/setup.lisp”. See the above referenced design specification for more details. The [ASDF-JAR contrib][2] provides a convenient mechanism for packaging Common Lisp systems encapsulated by ASDF into a jar that may subsequently used as the basis for loading these systems via the ASDF-JAR:ADD-TO-ASDF function. [2]: http://abcl.org/trac/browser/trunk/abcl/contrib/asdf-jar/README.markdown Both these options require that you know the absolute path of the deployed jar. JAR-PATHNAME objects follow CL:MERGE-PATHNAME conventions, so one may be able to figure out runtime locations based on the user home directory. […] Please let me know if I can be of further assistance here. -- "A screaming comes across the sky. It has happened before but there is nothing to compare to it now."
Hi Mark, I tried option one, using code File jarFile = new File(codeSource.getLocation().toURI().getPath()); String jarDir = jarFile.getParentFile().getPath(); String pathname = jarDir + "/JavaApplication17.jar!" + "/aima/quicklisp/setup.lisp"; JavaApplication17 d = new JavaApplication17(); d.Setup(); String str = "(load \"jar:file:/" + pathname + "\")"; str = str.replace("\\", "/"); d.execute(str); It gives this error "Cant ensure directory" [image: Inline image 1] On Sat, Aug 15, 2015 at 8:28 AM, Mark Evenson <evenson@panix.com> wrote:
On Aug 14, 2015, at 12:20, Hamda Binte Ajmal <hamda.binte.ajmal@gmail.com> wrote:
Hi, I was working on an application, that loads a few lisp files using lisp command (load "fullfilepath.lisp") from java using ABCL. This file in turn loads the other lisp files located in same folder hierarchy, and then i call lisp functions (defined in these files) from java and everything works perfect as long as I run the application from Netbeans. Close to deployment, I tested the application by running it from jar file, I found that there are issues with filepaths, as the files are not a part of file-system, and hence not accessible using a file-path. Does anyone has any idea how to fix this issue ?
ABCL has [extended the semantics of Lisp PATHNAME objects to be able to refer to files within jar files][1].
[1]:
http://abcl.org/trac/browser/trunk/abcl/doc/design/pathnames/jar-pathnames.m...
If you know the absolute path of the jar file locally, you may specify a file within via something that looks like: “jar:file:/absolute/path/to/file.jar!/path/within/jar/setup.lisp”. See the above referenced design specification for more details.
The [ASDF-JAR contrib][2] provides a convenient mechanism for packaging Common Lisp systems encapsulated by ASDF into a jar that may subsequently used as the basis for loading these systems via the ASDF-JAR:ADD-TO-ASDF function.
[2]: http://abcl.org/trac/browser/trunk/abcl/contrib/asdf-jar/README.markdown
Both these options require that you know the absolute path of the deployed jar. JAR-PATHNAME objects follow CL:MERGE-PATHNAME conventions, so one may be able to figure out runtime locations based on the user home directory.
[…]
Please let me know if I can be of further assistance here.
-- "A screaming comes across the sky. It has happened before but there is nothing to compare to it now."
-- Hamda Binte Ajmal +92 344 550 7680
participants (2)
-
Hamda Binte Ajmal
-
Mark Evenson