Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jdavidb (1361)

  (email not shown publicly)

J. David Blackstone has a Bachelor of Science in Computer Science and Engineering and nine years of experience at a wireless telecommunications company, where he learned Perl and never looked back. J. David has an advantage in that he works really hard, he has a passion for writing good software, and he knows many of the world's best Perl programmers.

Journal of jdavidb (1361)

Tuesday November 25, 2008
04:09 PM

Java should make complicated things possible

[ #37945 ]

How do you set environment variables in Java? You can't, because you shouldn't want to do that. Of course, I would really, really like to do that.

Perl is the only truly portable language I know. (I know there are others; I just don't know them.) It manages to do things as similarly as possible across an incredible range of platforms.

It seems that with JNI you could extend Java to do a lot of things it doesn't want to do. Most of these could be done quite portably, too. [Not being able to do them portably is the only reason I can see for these features to be kept out of Java itself.]

So, if I had a little extra time, I'd like to spend it releasing a jar full of classes to support simple portable extra features for Java, like:

Copying/renaming a file without having to read it block by block

Setting environment variables

Changing the current working directory

I guess if I was really flush for time I'd go see what it would take to get this going in the Java Community Process. Or fork the JDK.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Runtime.exec(String[] cmdarray, String[] envp, File dir) [] does envvars and working dirs for forked processes. Which is a little bit toward what you want...

    A major problem with envvars and working dirs as implemented in Perl, for example, is that they are process global. That wreaks havoc on the extreme isolation that Java strives for. So, I would argue that give Java's goals, the lack of %ENV and setcwd() is a feature.

    But the lack of copy? That's a real nuisance.

    • Yeah, I can set it for subprocesses, and I am. But I want to just set it for my current process so the subprocesses can inherit it. Also I am calling an ant build that unfortunately depends on environment variables (for the moment -- hopefully to be corrected next year, but there's no time right now), and since there is no way to set them, I had to rip out all of the nice code I had for calling that in my current process and pleasantly reading and organizing its output, and replace it with code to call it

      J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
      • A hack: when you first start the build, re-invoke ant via the java [] task with the proper envvars. Then all subsequent execs get that env.

        $work does a similar re-invoke to ensure that the build is running with the proper JDK and Ant (bundled with the code) to guarantee that all developers build with the selected JRE for each project.

  • I heard on a podcast recently that the NIO2 work that should (will?) be in Java 7 finally, finally has some sane file operations. (It's awful and idiotic that it's taken so long.) This has some examples: []
    • Thanks!

      I love this sentence:

      In Java 1.0 the language was so new we barely noticed that it had no reliable way to copy or move a file.

      I think those of us who were in an intoxicated crush with the language just noticed things like that and moved on. That is not a very inclusive "we" in that statement.

      J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers