0

Why would the file run with no problems when using Eclipse but when I create a jar file of the same program I can't run it locally on my pc?

This is the error I get where a is an input and signal.pl is a file I pass located in Desktop:

C:\Users\HP\Desktop>java -jar ADE2.jar a signal.pl
Exception in thread "main" org.jpl7.PrologException: PrologException: error(existence_error(source_sink, a), _0)
        at org.jpl7.Query.fetchNextSolution(Query.java:438)
        at org.jpl7.Query.hasMoreSolutions(Query.java:342)
        at org.jpl7.Query.oneSolution(Query.java:872)
        at org.jpl7.Query.hasSolution(Query.java:950)
        at ADE.executeGorgias(ADE.java:19)
        at ADE.main(ADE.java:41)
shaedrich
  • 5,457
  • 3
  • 26
  • 42
  • 1
    Well, it's opening file `a` and not finding it (which is kinda an "existence error" à la ISO: "An object on which an operation is to be performed does not exist."). Print the [absolute_file_name/3](https://eu.swi-prolog.org/pldoc/doc_for?object=absolute_file_name/3) before opening the file to check what Prolog thinks the location of file `a` is. – David Tonhofer Jun 16 '21 at 09:52

1 Answers1

0

I assume that you have two different working directories in your two scenaries.

SWI-Prolog provides the working_directory/2 predicate in the form of working_directory(-Old, +New).

As the documentation states:

Unify Old with an absolute path to the current working directory and change working directory to New. Use the pattern working_directory(CWD, CWD) to get the current directory.

Thus, I would suggest to test working_directory(CWD, CWD) in both cases to see if your working directory differs, which may lead to probelms when working with relative paths.

Edit: You can also use absolute_file_name/3 to ensure that your "Eclipse use case" and your "jar use case" resolve the file in the same way.

Markus Weninger
  • 11,931
  • 7
  • 64
  • 137