wood burning stoves 2.0*
The moose likes General Computing and the fly likes Setting environment via batch file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » General Computing
Bookmark "Setting environment via batch file" Watch "Setting environment via batch file" New topic
Author

Setting environment via batch file

John Storta Jr.
Greenhorn

Joined: Jul 26, 2009
Posts: 29
This is more of a Windows question, but it is regarding setting up Windows to do Java development so I am hoping I can get some guidance from the community.

I have historically done my development on Linux, but I have recently started developing on Windows. I scripts that I run for each project that set the environment variables for that project before I start working on it. I am having some trouble figuring out how to do this via batch file.

In linux, I have a script I source that sets the CLASSPATH dynamically using the following loop.



This allows me to add JARs to the classpath without having to manually update the script everytime. There are also similar constructs in the script that allow me to customize it based on the project I am working on at that moment.

In Windows, I am trying to do the same using a batch file, but it seems that a for loop in the batch file does not work unless I use the delayed expansion setting. But then it only updates it locally and I have to do other work arounds in order to update the global variable.


My question is basically to any Java programmers that do their work on Windows systems. Does anyone have any suggestions on how to configure the development environment using a batch file? Specifically, how can I convert the above to something that will work in a batch file?

Or if someone can think of a message board that is more appropriate for a question like this, please let me know.

Thanks

Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2849
    
  11

Hi John,

I feel your pain. I'm never happy when I have to write scripts in Windows. You might look into Ant or a similar tool to do your builds and even runs. It's much easier to build up class paths in Ant, and the build is then much easier to port over to other systems.

However, since this question is about Windows Command language, I'll move it over to our General Computing forum to see if someone can help you with it.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8876
    
    8

I use Ant to build my projects. It has a directive to add a directory to a classpath so you don't have to do individual JAR's.
Bonus: it's written in Java so you can use it on *nix. I use the same build script on developing with Windows as I do on my production Solaris servers. That way, when something goes wrong, I'm not wondering if it's a build problem. One less thing to check.

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5823
    
    7

I triple the recommendation for using Ant as a scripting language on Windows, especially for builds and packaging. I have used it that way for years.


JBoss In Action
John Storta Jr.
Greenhorn

Joined: Jul 26, 2009
Posts: 29
Thanks everyone. That is good advice.

I do use ant for building my apps, and I know I am only scratching the surface on what it can do for me. I will look more into moving some of my script stuff into it.


Thanks again.
 
Consider Paul's rocket mass heater.
 
subject: Setting environment via batch file