I downloaded the JSON library for Java from Maven Repo and installed the .JAR file at the Java library directory on UBuntu 14.04.
I tried compile a simple JAVA snippet for JSON parsing, but the compiler (javac) is telling me that the "org.json" library does not exist..
Is that a system CLASSPATH or a user CLASSPATH or did you set it specifically for this session? You should only set a CLASSPATH for the session with the -cp option or similar.
That CLASSPATH looks wrong, anyway; it should have the name of the .jar in, and should also include the current directory. Try
export CLASSPATH=.:/usr/share/java/json-20160212.jar to set that CLASSPATH for the lifetime of the current terminal. Read more about the CLASSPATH in the Java™ Tutorials. I am not sure about the setting that I gave you.
Ivan Leon wrote:
$ echo $CLASSPATH /usr/share/java
That classpath only specifies class files whose root is in that directory. To specify the jar file, you either have to explicitly have the jar file in the classpath, or use the "*" specifier to mention that the directory is for jar files.
I specified the .JAR and IT WORKED: $ javac -cp /usr/share/java/json-20160212.jar JsonParser.java
Thank you, guys!
Thank you, Code Ranch!
A brief (parentheses) here, just for reflection.
* In my opinion, Java Compiler could be more objective, not so trick, about this sort of situation.
Look at Google, and you will find thousands of Java developers (from beginners to not so beginners), having problems with this..
Thinking about Python: how many issues can you find in Google about module import, in comparison with Java.
For me that means something: maybe the approach of Java about compiling, could be revisited.
I don't know about python etc, but with Java dependencies are usually deployed with their app and not in a central area on a machine.
So for a web app, you have a lib directory which holds all the jar files used by that web app.
This means you don't pollute the machine with multiple versions of a jar file, possibly resulting in versioning issues between apps.
So, sticking that jar file in a common place would give me pause for thought, to say the least.
posted 3 years ago
That makes sense.
I'm not a Python expert but, I believe that for this approach, in order to keep specific libraries and their versions for a web app, it must be used the Virtual Env, which performs a kind of "chroot" for your application, totally isolating the app from the rest of the system.
I do believe that in Python, importing modules and libraries is much easier and straightforward, but maybe Java is more organized and correct about keeping the libraries in just one place, avoiding issues regarding library versions... ;)
Ivan Leon - @ivanleoncz
I wasn't selected to go to mars. This tiny ad got in ahead of me: