Okay, I’m very new to linux and command line, and fairly new to java. I got an internship building a java program. I finally got it done on my machine (windows) and now I have to migrate it to a linux machine to test and then have it run as an executable. I have done much reading and researching on linux and understanding classpaths but it is still all very hard to fully comprehend. It’s just not clicking for me yet. Can anyone explain the purpose of classpath in a simplified way using examples? One of the most confusing aspects to me is actually defining the physical path to the jar. Do I start all the way from usr or do I only need to begin from the jvm folder? If it matters, my java program is not located in the jvm folder. Can anyone shed some light for me?
EDIT: thank you guys very much for your help, I can’t say that I’m fully in the clear but my understanding of my situation is a lot better.
You use the
-classpathargument. You can use either a relative or absolute path. What that means is you can use a path relative to your current directory, OR you can use an absolute path that starts at the root/.Example:
In this example the
mainfunction is located inMyMainClassand would be included somewhere in the jar file.For compiling you need to use
javacExample:
You can also specify the classpath via the environment variable, follow this example:
For any normally complex java project you should look for the ant script named
build.xml