I tried this but I was not able to run the jar file from a different folder even after setting the classpath.
Marilyn de Queiroz
Joined: Jul 22, 2000
Is MyJar.jar a jar you created or a third party jar? If it is someone else's jar that you're using, I think that there's nothing you can do. If it is your own jar, you might be able to change the manifest to include the directories/files that you need.
This has nothing to do with the classpath. When you execute "java -jar <file>" you need to give it a valid file, whether it's a relative path or an absolute path. If you want to run it from a different directory that has a relative path that will be consistent then use that, otherwise you'll have to use an absolute path. For example, if you have your program setup such that there's a script in the directory "MyProgram" and your JAR files were all in "MyProgram\data\" then you would run it with "java -jar data\MyFile.jar" telling it to look in the data directory for MyFile.jar. If you wanted to use an absolute path it might look like "java -jar C:\Program Files\MyProgram\data\MyFile.jar" if you had your MyProgram directory under Program Files on the C drive.