aspose file tools*
The moose likes Java in General and the fly likes Request suggestions for improving tools Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Request suggestions for improving tools" Watch "Request suggestions for improving tools" New topic
Author

Request suggestions for improving tools

Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 686
Hi,

I've written some tools to help me resolve classpath problems on a Windows system. However, I think they are too hard for a beginning programmer to use. Can you give me some ideas for making them easier to use?

The one tool: CheckClasspath is used to test that the classpath reaches a class file. It uses the current environment CLASSPATH value and the package of the class file to see if there is a path to the class. The problem is getting the current CLASSPATH value into the program. I have several ways to start execution of the program. When a program is started with java -jar the classpath is ONLY to the jar.

The one I use the most is from the right-click context menu when I right-click on a class file. The problem here is how can the program get the CLASSPATH value? The only way I've found is to call a batch file which can use the %CLASSPATH% variable to pull in and pass the classpath to the program as a parameter.
The batch file has the following commandline:
java.exe -jar %JAVA_RUN%\CkClasspath.jar -CP "%CLASSPATH%" %1 %2 %3

Another way is from a shortcut. Here the OS will substitute the classpath for the %CLASSPATH% value in the program parameters on the commandline.
The third way is to start the program from the batchfile.

Some people advocate NOT using the CLASSPATH environment variable. The consequences of that is that you have to type in a new classpath every time you create a batch file or shortcut and I make my share of typing errors.
The java program does NOT complain if you execute it with a bad/non-existent path. Too bad, that would have saved me hours!!!

An example usage of CheckClasspath -> create a batch file to execute a class file:
Create a batch file with the line: java -cp <cp> <path>
Open the CheckClasspath program and use it to "Open" the class file. It will display the classpath.path to the file.
Select the 'Copy Classpath to CB' menuitem and paste/replace <cp> above.
Select the' Copy package to CB' menuitem and paste/replace <path> above.

I suppose some of the IDEs will do all this for you.

What ways have others found to verify correct classpath settings when creating commandlines for executing java programs? java.exe is no help there.

These programs can be downloaded from:
http://users.mo-net.com/normandpaula/NormsClassPathTools.html

Thanks,
Norm
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
You can get the CLASSPATH programmatically by using the System.getenv(). Check out the API docs for the System class for more details.

Layne


Java API Documentation
The Java Tutorial
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 686
I guess your doc is older than mine. That method has been depreciated and no longer works.
I get the following when trying to execute it:

java.lang.Error: getenv no longer supported, use properties and -D instead: CLASSPATH
at java.lang.System.getenv(Unknown Source)
at Testxxx.main(Testxxx.java)
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

It may also be that Layne's documentation is newer than yours. getenv() used to be deprecated; it's been undeprecated in Tiger and works fine!


[Jess in Action][AskingGoodQuestions]
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by Ernest Friedman-Hill:
It may also be that Layne's documentation is newer than yours. getenv() used to be deprecated; it's been undeprecated in Tiger and works fine!


*ack* Now that seems like a bad way to maintain a public API!

Layne
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

Poor Sun, they're damned if they do, and damned if they don't. This was undeprecated due to public outcry. It's actually not the first deprecated, then undeprecated API, although I can't remember what the other example is at this moment.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923


Some people advocate NOT using the CLASSPATH environment variable. The consequences of that is that you have to type in a new classpath every time you create a batch file or shortcut and I make my share of typing errors.


You could set a indirect variable ...

... and use it, to create your batch-file:

to avoid retyping a lot of stuff over and over.

Another approach would be to have a template-batch-file, where it is hardcoded inside:

(which is not tested - I got no win by hand).
It might be done more elegant if you know how to threat cmd.exe a bit sophisticated, and I guess you got my point.


http://home.arcor.de/hirnstrom/bewerbung
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Request suggestions for improving tools