{"id":24,"date":"2016-07-13T15:16:32","date_gmt":"2016-07-13T12:16:32","guid":{"rendered":"http:\/\/siteblog.tuc.gr\/nispanoudakis\/?p=24"},"modified":"2021-09-24T16:52:13","modified_gmt":"2021-09-24T13:52:13","slug":"debugging-a-java-application-querying-prolog-using-eclipse","status":"publish","type":"post","link":"https:\/\/siteblog.tuc.gr\/nispanoudakis\/2016\/07\/13\/debugging-a-java-application-querying-prolog-using-eclipse\/","title":{"rendered":"Debugging a Java application querying Prolog using Eclipse"},"content":{"rendered":"<p>You normally start a new eclispe java project, let&#8217;s name it <em>TestPrologInterface<\/em> (see Figure 1 below).<\/p>\n<p>To use JPL you need to import the jar file in your project. You right-click on the project&#8217;s name and click on Properties (or from the Eclipse menu bar you select <em>Project-&gt;Properties<\/em>). Then on the <em>Libraries<\/em> tab you click on the <em>Add External JARs&#8230;<\/em> button and select the jpl.jar (see Figure 2 below).<\/p>\n<p>Then, you can add a new class and paste in the code from <a href=\"http:\/\/siteblog.tuc.gr\/nispanoudakis\/2016\/05\/13\/quering-prolog-from-java\/\">my previous blog entry<\/a>&nbsp;(see Figure 3 below).<\/p>\n<p>Subsequently, you will need to setup a run configuration for executing\/debugging your project. To do that you select on the Eclipse menu bar the <em>Run-&gt;Run Configurations&#8230;<\/em>&nbsp;option, then you right-click on <em>Java application<\/em> and select <em>New<\/em>. Then you add the names of the project and main class (see Figure 4 below).<\/p>\n<p>The next thing to do is define the right environment variables. To do that you need a command prompt where you will execute the command:<\/p>\n<pre>  \"c:\\Program Files\\swipl\\bin\\swipl.exe\" --dump-runtime-variables=cmd\n<\/pre>\n<p>See the resulting environment variables in Figure 5 below.<\/p>\n<p>Now you are ready to configure the variables on eclipse. In the run configuration go to the <em>Environment<\/em> tab&nbsp;and then add the variables one by one (click <em>Add<\/em> and insert the information from the previous screen, from each line the left hand side as name and the right hand side as value). You can see the results in Figure 6 below.<\/p>\n<p>Finally, you run the configuration by clicking on <em>Run<\/em>&nbsp;(bottom right). The result is shown at the bottom of Figure 7, where you see the eclipse screenshot including the source code.<\/p>\n<p>If you want to export the project to a runnable jar file you right click on the project name and select&nbsp;<em>Export<\/em>. In the dialog that opens you select&nbsp;<em>Java-&gt;Runnable jar file<\/em>. In the next dialog you define the name of the exported jar and don&#8217;t forget to check the&nbsp;<em>Package required libraries into generated JAR<\/em> if you want the jpl.jar file to be included (see a screenshot in Figure 8).<\/p>\n<p>Now you are ready to distribute your application. Distribute it with the batch file that I used in my <a href=\"http:\/\/siteblog.tuc.gr\/nispanoudakis\/2016\/05\/13\/quering-prolog-from-java\/\">previous blog entry<\/a>.<\/p>\n<p>Figure 1: Create a new project dialog<br \/>\n<a href=\"http:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/new_project.png\"><img loading=\"lazy\" decoding=\"async\" width=\"569\" height=\"716\" class=\"alignnone size-medium wp-image-51\" src=\"http:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/new_project.png\" alt=\"new_project\" srcset=\"https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/new_project.png 569w, https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/new_project-238x300.png 238w\" sizes=\"auto, (max-width: 569px) 100vw, 569px\" \/><\/a><\/p>\n<p>Figure 2: Add the JPL JAR file to library<br \/>\n<a href=\"http:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/add_external_jars.png\"><img loading=\"lazy\" decoding=\"async\" width=\"721\" height=\"514\" class=\"alignnone size-medium wp-image-52\" src=\"http:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/add_external_jars.png\" alt=\"add_external_jars\" srcset=\"https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/add_external_jars.png 721w, https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/add_external_jars-300x214.png 300w\" sizes=\"auto, (max-width: 721px) 100vw, 721px\" \/><\/a><\/p>\n<p>Figure 3: New class dialog<br \/>\n<a href=\"http:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/new_class.png\"><img loading=\"lazy\" decoding=\"async\" width=\"542\" height=\"637\" class=\"alignnone size-medium wp-image-54\" src=\"http:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/new_class.png\" alt=\"new_class\" srcset=\"https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/new_class.png 542w, https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/new_class-255x300.png 255w\" sizes=\"auto, (max-width: 542px) 100vw, 542px\" \/><\/a><\/p>\n<p>Figure 4: Create a new run configuration dialog<br \/>\n<a href=\"http:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/new_run_conf.png\"><img loading=\"lazy\" decoding=\"async\" width=\"992\" height=\"711\" class=\"alignnone size-medium wp-image-57\" src=\"http:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/new_run_conf.png\" alt=\"new_run_conf\" srcset=\"https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/new_run_conf.png 992w, https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/new_run_conf-300x215.png 300w\" sizes=\"auto, (max-width: 992px) 100vw, 992px\" \/><\/a><\/p>\n<p>Figure 5: Using the command line to find the SWI-Prolog environment variables<br \/>\n<a href=\"http:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/find_variables.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1312\" height=\"450\" class=\"alignnone size-medium wp-image-58\" src=\"http:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/find_variables.png\" alt=\"find_variables\" srcset=\"https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/find_variables.png 1312w, https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/find_variables-300x103.png 300w, https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/find_variables-1024x351.png 1024w\" sizes=\"auto, (max-width: 1312px) 100vw, 1312px\" \/><\/a><\/p>\n<p>Figure 6: The environment tab in the new run configuration dialog<br \/>\n<a href=\"http:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/new_run_conf_env.png\"><img loading=\"lazy\" decoding=\"async\" width=\"992\" height=\"711\" class=\"alignnone size-medium wp-image-56\" src=\"http:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/new_run_conf_env.png\" alt=\"new_run_conf_env\" srcset=\"https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/new_run_conf_env.png 992w, https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/new_run_conf_env-300x215.png 300w\" sizes=\"auto, (max-width: 992px) 100vw, 992px\" \/><\/a><\/p>\n<p>Figure 7: The java class and the execution output<br \/>\n<a href=\"http:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/code_and_run_results.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"743\" class=\"alignnone size-medium wp-image-55\" src=\"http:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/code_and_run_results.png\" alt=\"code_and_run_results\" srcset=\"https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/code_and_run_results.png 1000w, https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/code_and_run_results-300x223.png 300w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/a><\/p>\n<p>Figure 8: The runnable JAR export dialog<br \/>\n<a href=\"http:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/runnable_jar.png\"><img loading=\"lazy\" decoding=\"async\" width=\"570\" height=\"550\" class=\"alignnone size-medium wp-image-64\" src=\"http:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/runnable_jar.png\" alt=\"runnable_jar\" srcset=\"https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/runnable_jar.png 570w, https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-content\/uploads\/sites\/58\/2016\/07\/runnable_jar-300x289.png 300w\" sizes=\"auto, (max-width: 570px) 100vw, 570px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You normally start a new eclispe java project, let&#8217;s name it TestPrologInterface (see Figure 1 below). To use JPL you need to import the jar file in your project. You right-click on the project&#8217;s name and click on Properties (or from the Eclipse menu bar you select Project-&gt;Properties). Then on the Libraries tab you click &hellip; <a href=\"https:\/\/siteblog.tuc.gr\/nispanoudakis\/2016\/07\/13\/debugging-a-java-application-querying-prolog-using-eclipse\/\" class=\"more-link\">\u03a3\u03c5\u03bd\u03ad\u03c7\u03b5\u03b9\u03b1 \u03b1\u03bd\u03ac\u03b3\u03bd\u03c9\u03c3\u03b7\u03c2 <span class=\"screen-reader-text\">Debugging a Java application querying Prolog using Eclipse<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":77,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,10,2,13,36,14,8],"tags":[],"class_list":["post-24","post","type-post","status-publish","format-standard","hentry","category-eclipse","category-jar","category-java","category-jpl","category-prolog","category-run-configuration","category-windows"],"_links":{"self":[{"href":"https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-json\/wp\/v2\/posts\/24","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-json\/wp\/v2\/users\/77"}],"replies":[{"embeddable":true,"href":"https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-json\/wp\/v2\/comments?post=24"}],"version-history":[{"count":10,"href":"https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-json\/wp\/v2\/posts\/24\/revisions"}],"predecessor-version":[{"id":176,"href":"https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-json\/wp\/v2\/posts\/24\/revisions\/176"}],"wp:attachment":[{"href":"https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-json\/wp\/v2\/media?parent=24"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-json\/wp\/v2\/categories?post=24"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/siteblog.tuc.gr\/nispanoudakis\/wp-json\/wp\/v2\/tags?post=24"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}