Setting windows environment variable through Java code...
The below is a simple Java class code which will pass few parameters to a method which get's validated against null and empty conditions and then a process will be started with those values.
Basically one batch script or shell script gets run depending on the OS name found from environment .. it sets two environment variables in the operating system.
The below is a simple Java class code which will pass few parameters to a method which get's validated against null and empty conditions and then a process will be started with those values.
Basically one batch script or shell script gets run depending on the OS name found from environment .. it sets two environment variables in the operating system.
import java.io.BufferedReader; import java.io.File; import java.io.InputStreamReader; import java.util.Map; public class IfixConfig { /** * @param args * @param MYPRODUCT_Home * @param WAS_username * @param WAS_password * @param iFixLocation */ public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Starting IFIX configuration"); String MYPRODUCT_Home = "C:\\Program Files\\XYZ\\MYPRODUCT"; String WAS_username = "smadmin"; String WAS_password = "g0vmware"; String iFixLocation = "C:\\Program Files\\XYZ\\MYPRODUCT\\ui\\ifixes\\3.1.0.0\\0001"; int result = ifixConfig(MYPRODUCT_Home, WAS_username, WAS_password, iFixLocation); System.out.println("Result:" + result); } private static int ifixConfig(String MYPRODUCT_Home, String wAS_username, String wAS_password, String iFixLocation) { int resultCode = -1; try { System.out.println(MYPRODUCT_Home + wAS_username + wAS_password + iFixLocation); ProcessBuilder pb = null; String postConfigScript = iFixLocation + "/post_install_configure."; if (wAS_username != null && !(wAS_username.isEmpty()) && wAS_password != null && !(wAS_password.isEmpty())) { System.out.println("WAS username and passwords provided"); if (System.getProperty("os.name").startsWith("Windows")) { postConfigScript = postConfigScript + "bat"; pb = new ProcessBuilder("CMD.exe", "/C", postConfigScript); } else { postConfigScript = postConfigScript + "sh" ; pb = new ProcessBuilder(postConfigScript); } System.out.println("Post config script:"+postConfigScript); pb.directory(new File(iFixLocation)); pb.redirectErrorStream(true); Mapenv = pb.environment(); env.put("MYPRODUCT_WAS_USERNAME",wAS_username); env.put("MYPRODUCT_WAS_PASSWORD", wAS_password); Process process = pb.start(); BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while ((line = in.readLine()) != null) { System.out.println(line); if ( line.equals("BUILD SUCCESSFUL")){ resultCode = 0 ; } } } else { System.out.println("WAS username and password should not be empty"); } } catch (Exception e) { System.out.println(e); } return resultCode; } }
Wednesday, March 20, 2013
//
Labels:
Java
//
1 comments
//
1 comments to "Setting windows environment variable through Java code"
Post a Comment
Whoever writes Inappropriate/Vulgar comments to context, generally want to be anonymous …So I hope U r not the one like that?
For lazy logs, u can at least use Name/URL option which doesn’t even require any sign-in, The good thing is that it can accept your lovely nick name also and the URL is not mandatory too.
Thanks for your patience
~Krishna(I love "Transparency")
Popular Posts
-
The best solution to know about these init levels is to understand the " man init " command output on Unix. There are basically 8...
-
How to Unlock BSNL 3G data card to use it with Airtel and Vodafone Model no : LW272 ? How to unlock BSNL 3G data card( Model no : LW272 )us...
-
How to transfer bike registration from one State to other (Karnataka to Andhra)?? Most of us having two wheelers purchased and registered in...
-
ఓం శ్రీ స్వామియే శరణం ఆయ్యప్ప!! Related posts : Trip to Sabarimala - Part 1 Trip to Sabarimala - Part 2 Ayappa Deeksha required things...
-
Following are some of interesting blogs I found till now ...please comment to add your blog here. Blogs in English : http://nitawriter.word...
Popular posts
- Airtel and vodafone GPRS settings for pocket PC phones
- Andhra 2 America
- Ayyappa Deeksha required things
- Blogs I watch !
- Captions for your bike
- DB2 FAQs
- Deepavali Vs The Goddes of sleep
- ETV - Dhee D2 D3
- Evolution of smoking in India Women
- How to make credit card payments?
- init 0, init 1, init 2 ..
- Java-J2EE interview preparation
- mCheck Application jar or jad download
- My SQL FAQs
- My Travelogues
- Old is blod - New is italic
- Online pay methids for credit cards
- Oracle FAQs
- Pilgrimages
- Smoking in Indian Women
- Technology Vs Humans
- Twitter feeds for all Telugu stars on single page.
- Unix best practices
- Unix FAQs
Haris says:
I have been following your post from 2010, my last year of college.