Where do java packages live on a Linux system? Org.json package does not exist Error using javac

I am trying to compile a library that I wrote using javac and I get an error: package org.json does not exist . My program includes org.json.JSONArray and org.json.JSONException .

I have this package installed on my computer because I have successfully compiled Android applications that import the org.json libraries. I am sure that all I need to do is specify -classpath , but I could not find where these files live on my system (ubuntu 10.10 64-bit sun-java6).

I could not find them in my own system, I downloaded org.json files from here , but I could not compile them separately because they were dependent on each other.

So, I have a couple of questions:

  • Does anyone know where the org.json package lives from the android sdk install?
  • Where can I find a tutorial explaining these basic concepts regarding compilation and javac.
+4
source share
2 answers

Wherever. What you need to do is check the CLASSPATH variable and make sure that it contains the directory with your library.

Here is the first:

  $ echo $CLASSPATH 

and you will see your path to the class as it is.

Now you need to find the jar file containing org.json; refer to the documentation, but it might just be like json.jar . On most LINUX systems, you can simply run

  $ locate json.jar 

And you will get the path name for jarfile. Make sure this path is part of your CLASSPATH and you will be in a fat city.

Oh, and Getting Started Tutorials at Sun Oracle are the easiest place to start.


Actually, looking at the files, they cannot be packaged as a jar file. In this case, you want to put them in your sources, starting from some top directory ( src in this example.)

  /src /org/json/ ... put the json files here ... put your files here 

and when you compile, they will all be included, which will solve all the dependencies.

Again, a place to look for the first steps is a tutorial.

+2
source

No matter what external jars you need to compile, they must be in the class path when compiling. The most non-invasive way to do this is to add these elements to the javac command line, for example

javac -classpath /path/to/json.jar;. -g YourClass.java

or, more likely, if you are using an IDE, add these banks to your bans with a link to a project in your IDE.

As a rule, it is not recommended to pollute the global variable $CLASSPATH , because then it pulls for everything that you do with java, which can cause unintended conflicts.

+3
source

Source: https://habr.com/ru/post/1341469/


All Articles