I don't like setting CLASSPATH. CLASSPATH is a global variable and as such it is evil:
- If you modify it in one script, suddenly some java programs will stop working.
- If you put there the libraries for all the things which you run, and it gets cluttered.
- You get conflicts if two different applications use different versions of the same library.
- There is no performance gain as libraries in the CLASSPATH are not shared - just their name is shared.
- If you put the dot (.) or any other relative path in the CLASSPATH that means a different thing in each place - that will cause confusion, for sure.
Therefore the preferred way is to set the classpath per each run of the jvm, for example:
Copyjava -Xmx500m -cp ".:../somejar.jar:../mysql-connector-java-5.1.6-bin.jar" "folder.subfolder../dit1/some.xml
If it gets long the standard procedure is to wrap it in a bash or batch script to save typing.
Answer from flybywire on Stack OverflowI don't like setting CLASSPATH. CLASSPATH is a global variable and as such it is evil:
- If you modify it in one script, suddenly some java programs will stop working.
- If you put there the libraries for all the things which you run, and it gets cluttered.
- You get conflicts if two different applications use different versions of the same library.
- There is no performance gain as libraries in the CLASSPATH are not shared - just their name is shared.
- If you put the dot (.) or any other relative path in the CLASSPATH that means a different thing in each place - that will cause confusion, for sure.
Therefore the preferred way is to set the classpath per each run of the jvm, for example:
Copyjava -Xmx500m -cp ".:../somejar.jar:../mysql-connector-java-5.1.6-bin.jar" "folder.subfolder../dit1/some.xml
If it gets long the standard procedure is to wrap it in a bash or batch script to save typing.
It's always advised to never destructively destroy an existing classpath unless you have a good reason.
The following line preserves the existing classpath and adds onto it.
Copyexport CLASSPATH="$CLASSPATH:foo.jar:../bar.jar"
I'm not a Java programmer, so I don't know the correct value for CLASSPATH. But, you seem to. You can add it to ~/.bashrc like so:
CLASSPATH=/path/to/1:/path/to/2:/etc
The change will take effect globally the next time you log in. However, it will take effect immediately in new shells.
Additionally, if you want to set it for just one particular command, do this:
CLASSPATH=/something command-here arg1 arg2
A third way would be to create a wrapper script, which would be appropriate if you needed to set multiple variables or if you needed to determine appropriate values programmatically:
#!/bin/bash
export CLASSPATH=/something
export ANOTHER_ENV_Variable=foo
exec your_fancy_program "$@"
that's what happened with me.. i left empty spaces while typing.. it fixed when i removed spaces.
1) if you want to set classpath permanently then 1) find out where java is installed.. you may use " whereis java " openjdk-7/6 is in /usr/lib/jvm/.....
2) we need to set up CLASSPATH in /etc/environment
sudo gedit /etc/environment
3) add the following likes .. ( DONT LEAVE ANY SPACES WHILE TYPING)(customize according to your java version and installation) (this home path is for open jdk 7)
JAVA_HOME="/usr/lib/jvm/java-7-openjdk-i386/bin"
export JAVA_HOME
CLASSPATH=".:/usr/lib/jvm/java-7-openjdk-i386/lib:/home/laptop/Desktop/a2"
export CLASSPATH
separate directory by ":"
Videos
I read this:
In Java, the term "classpath" refers to a parameter that specifies a set of directories or JAR (Java Archive) files where the Java Virtual Machine (JVM) and Java compiler should look for classes and resources when running or compiling Java applications
But where does this classpath comes into existence? If you for example have a completely vanilla project with some source code, and want to compile it manually with javac, does this notion of class path exist, for example?
How does it work in the context of build automation tools like Maven?And in an intelliJ project, for example, where can I find the class path and how does it work relatively to the project?
I've read a lot about what it does, but not what it exactly is and I would really appreciate some clarification!
Edit: I tried to look at the docs (oracle for example), but even there it's all kind of vague.