0

Havnt used java in 3 years or so. Found something I needed to do and thought I had some good old code I could reuse. Got everything working the way I need to but am a little thrown off on how jar imports seem to have changed a bit with the module stuff in this newer version of java since last touching it. Runs fine within eclipse but every time I try to run on command Line I get 12-15 errors. They are all something like this....

Driver.java:5: error: package org.json.simple.parser does not exist
import org.json.simple.parser.ParseException;
                             ^
.\jsonParse.java:10: error: package org.json.simple does not exist
import org.json.simple.JSONArray;
                      ^
.\jsonParse.java:11: error: package org.json.simple does not exist
import org.json.simple.JSONObject;
                      ^
.\jsonParse.java:12: error: package org.json.simple.parser does not exist
import org.json.simple.parser.JSONParser;
                             ^
.\jsonParse.java:13: error: package org.json.simple.parser does not exist
import org.json.simple.parser.ParseException;
                             ^
.\jsonParse.java:17: error: cannot find symbol
        public static ArrayList<Products> parser(String url) throws FileNotFoundException, IOException, ParseException {

Obviously its complaining about references to json-simple-1.1.jar but I have that sitting in the referenced Library folder within a java project in eclipse, and it is connected under classpath in run config.

Here is the project structure

In eclipse->
DataFeedProject (c:/myCode/DataFeedProject)

    src
      driver.java (main)
      jsonParser.java
      Products.java
      apiClient.java
      xmlGenerator.java
    JRE System Library [JavaSE-17]
    Referenced Libraries
       json-simple-1.1.jar (c:/myCode)
    xmlOutput.xml
    productStatus.txt


file explorer -> these four are only visible in file explorer

    .settings (containing eclipse resources)
    bin (all the .class files eclipse generated)
    .classpath
    .project

I have spent more time than I would like to admit trying to figure out why I cant get it running from command line. Need a compiled version to send off to server via ssh where I will only be able to run via cmd. Feel like I have exhausted about ever combination of javac -d path -cp path Driver.java etc etc.

Appreciate any help. Thanks

tw123
  • 1
  • 1

1 Answers1

1

The problem will be that you have given an incorrect classpath. So based on the details in the question, you need to do this.

Find out the full pathname for the "json-simple-1.1.jar" file, then

  cd c:/myCode/DataFeedProject/src
  javac -d ../bin -cp <jar-pathname> *.java

The thing is that if javac cannot find a JAR that is supposedly on the classpath ('cos you gave an incorrect path) it doesn't tell you. It just ignores it.

If you do the above without -d ../bin, the compiler will put the .class files into the current directory, which is not what you want.

(I can't actually check this, 'cos ... Windows :-( )

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Ok this makes sense and if I compile with the wildcard * it does seem to compile without error. However trying to run it on the next line seems to claim it cannot find any of the files or load the main class whether I stay in src, cd bin or try to reference bin path location in the program to run? – tw123 Jul 28 '22 at 03:52
  • Seeminly can only compile with the wildcard. Pointing to bin and my jar file still tries to compile my main class driver with errors like it still ignors the jar – tw123 Jul 28 '22 at 03:59
  • Gave it another shot before bed. Basically I believe something else is going on. due to this error im getting now. Driver.java:5: error: package org.json.simple.parser does not exist import org.json.simple.parser.ParseException; ^ Driver.java:39: error: cannot find symbol } catch (ParseException e) { ^ symbol: class ParseException location: class Driver 2 errors I know there is a Parse in that library. Not sure if its picking up a different jar or an outdated jar or what but something seems wrong here – tw123 Jul 28 '22 at 04:49
  • Seems to be a version issue possibly compiler is version 62 java 18 while build is java 17 version 61 compiler in eclipse – tw123 Jul 28 '22 at 14:48