Avatar billede fredand Forsker
11. maj 2009 - 15:39 Der er 10 kommentarer og
1 løsning

How to set a env permanent from cmd?

Hello guys!

I'm programming in Java most of my work.
Right now we switch between 2 projects. One using 1.4 and one is using 1.6.

Since I use maven I need to to have JAVA_HOME set to the version to use.

I would love to get a bat script that does:
set JAVA_HOME=path\to\1.4

and an other script that does:
set JAVA_HOME=path\to\1.6

...so it gets easy to switch just by clicking a each bat-file.

But a problem seems to be that the change is not permanent.

If I run the same command from a cmd and then closes the cmd, the change is not still there when I open I new cmd.

Hope you see my point.

So if you got any idea how to solve this it would be great.

Best regards
Fredrik
Avatar billede arne_v Ekspert
11. maj 2009 - 15:55 #1
I think you will need to update the registry:

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment\JAVA_HOME
Avatar billede fredand Forsker
11. maj 2009 - 16:04 #2
Hello!

Sounds great!
I'm on it!

I'll be back!
/Fredrik
Avatar billede fredand Forsker
11. maj 2009 - 16:39 #3
Hello Arne!

Your solution did what it should!
So please give a svar so I can reward you!


To create the script I changed the JAVA_HOME in the registry and saved 2 different files, one for 1.4 and one for 1.6.

When I import them, the registry gets updated, and when I look under my computer/properties/advanced/env..

... But strangely when I do a "echo %JAVA_HOME%" it does not change even though I close and open new cmd:s.

If you got any extra ideas I'm most thnakfull!

Best regards
Fredrik

Btw One reson for this is that my IE seems stuck with applet-engine for 1.4 even though I told it to use 1.6
... so when I try to login to JBoss 5 and it's JBoss Web Console it will not start the applet. I guess it needs 1.6 but as I said it seems to only use 1.4.

Best regards
Fredrik
Avatar billede arne_v Ekspert
12. maj 2009 - 01:58 #4
Regarding why it is not working for new CMD's: can you update CurrentControlSet ?
Avatar billede fredand Forsker
12. maj 2009 - 08:54 #5
Good morning!

Very interesting but what is the "CurrentControlSet"?

Btw do you know how IE determens the applet-viewer/engine to use?

It seems that it not use JAVA_HOME, and I can not find anything in PATH that indicates what to use.
(Now my JAVA_HOME is set to 1.6, but IE uses 1.4 in some way)

Best regards
Fredrik
Avatar billede fredand Forsker
12. maj 2009 - 12:06 #6
Hello!

I found out what "CurrentControlSet".is.
(http://support.microsoft.com/kb/100010)

But I then thought that I would find my JAVA_HOME there also, but my JAVA_HOME seems only be available under:

[HKEY_USERS\S-1-5-21-3734984382-2249190146-137403791-2401\Environment]
"JAVA_HOME"="C:\\Program\\Java\\jdk1.6.0_07"

Tricky!

Best regards
Fredrik
Avatar billede fredand Forsker
12. maj 2009 - 12:24 #7
Aha!

Seems like I can change the settings for which jre (1.4, 1.6) for IE in the Java Control from the "system tray" (think it is called system tray).

Back to the cmd problem then.

Best regards
Fredrik
Avatar billede fredand Forsker
12. maj 2009 - 12:43 #8
Hmm!

Seems that my above change for IE does not work.
IE still uses 1.4 for the controlpanel in some way, but I can change to 1.6. But applet written for 1.6 still does not work.

In my firefox it in some way uses 1.6 for the controlpanel and all applet works.

Would love to be able to change it for IE as well.

Best regards
Fredrik
Avatar billede arne_v Ekspert
13. maj 2009 - 01:48 #9
Hmm.

Try look at the keys in:

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Java*\CLSID
Avatar billede fredand Forsker
24. maj 2009 - 19:15 #10
Hello!

I never managed to get this right, my solution was to set it for each cmd.

But please give a svar arne, your answers increased my knowledge about the register so it was most welcome.

Bets regards
Fredrik
Avatar billede arne_v Ekspert
25. maj 2009 - 14:14 #11
OK
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester