CLASSPATH for application

Specifically I read the documentation that files are loaded from the CLASSPATH. Naturally I don't want to change the CLASSPATH because a specific application requires it. I would like to change the CLASSPATH specifically for a specific application. Is that possible?

6 comments

I can't fully undestand your question
If you want to load your class with special class loader ,you can extends the classlaoder in the jdk,or simply use it ,such as URLClassLoader....
BTW ,not all classes are loaded from classpath, see more about the bootstrap classload...extension classloader....classpath classloader(system classloader),thread classloader ...

0

I didn't want to get into the nitty gritty of my application but try to extract the details as needed and think of it as a general problem.

This is a Hadoop/HDFS application. I have code like:

 Configuration conf = new Configuration();
FileSystem hdfs = FileSystem.get(conf);
FileSystem local = FileSystem.getLocal(conf);
Path inputDir = new Path(args[0]);
Path hdfsFile = new Path(args[1]);

From the documentation on the 'Configuration' class I see that the files that it needs to form a configuration are found by searching the CLASSPATH. For this application I might put the files in one location and for another application I put them someplace entirely different. I don't want the environment variable CLASSPATH to contain the union of all possible paths to the configuration files for Hadoop. I would like to be able to specify that location per application. Unfortunately there isn't an argument to the constructor for the Configuration class that specifies the location of the needed configuration files. It apparently uses the CLASSPATH to find the appropriate files. So my question is how do I modify the CLASSPATH *per application* so the configuration files are found?

0

I have never use this framework before.
Download the src and read the  source code

11.jpg

Only the "addResources(String) will examine the ClassPath..
You can use addResource(Path) ,AddResource(URL).... and so on
They don't examine the Classpath..

  Configuration conf = new Configuration();
  conf.addResource(aPath)..

22.jpg

0

Excuse the ignorace but the "resource" path that you set with addResource(Path file) is that the folder path or should I add a separate path for each of the files in the folder? I am sorry but I don't understand what they are calling a resource and what Jave is calling a resource.

0

    As you said "I don't want the environment variable CLASSPATH to contain the union of  all possible paths to the configuration files for Hadoop. I would like  to be able to specify that location per application"
    So you want to load specify resource for each application...it is correct to add different resource to "Configuration".
    11.jpg

    Use  loadisForEeachApp()  to loader different resource for every application.
BTW ,can you tell me the detail to load the resource for your applicatoins?
For example, Application app1,Application app2, can you explain how to load the resource for "app1","app2" ?
Maybe you have to add each file to configuraton rather than a folder...

0

About the Path,maybe it can't be a folder....
Class Configuration  have  many  "setter" methods to add resource, it is easy to add all files under folder  ,right?
I don't know how to defined "Resource" in java, maybe properites files,pictures ,datasource ..and so on...In my opinion ,everything is resource in java....
But in this framework,i guess that it means "configuration fiels..."

11.jpg

0

Please sign in to leave a comment.