Skip to content

Commit

Permalink
modify README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ystyle committed Jul 22, 2017
1 parent 7f76d6a commit 9471acf
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 14 deletions.
115 changes: 115 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# JDK Version Manager (JVMS) for Windows

Manage multiple installations of JDK on a Windows computer.
[JVMS](https://github.com/ystyle/jvms), [Download Now](https://github.com/ystyle/jvms/releases)!


There are situations where the ability to switch between different versions of JDK can be very
useful. For example, if you want to test a project you're developing with the latest
bleeding edge version without uninstalling the stable version of JDK, this utility can help.

### Installation
- [Download Now](https://github.com/ystyle/jvms/releases)
- decompression zip and copy jvms.exe to a path what you want
- run cmd or powershell as administrator
- cd to folder where `jvms.exe` in
- run `jvms.exe init`
- Setup is complete ! Switch and install jdk see below

![](images/powershell_2017-07-23_00-38-13.png)


### Usage
```shell
NAME:
jvms - JDK Version Manager (JVMS) for Windows

USAGE:
jvms.exe [global options] command [command options] [arguments...]

VERSION:
2.0.0

COMMANDS:
init Initialize config file
list, ls List the JDK installations.
install, i Install remote available jdk
switch, s Switch to use the specified version.
remove, rm Remove a specific version.
rls Show a list of versions available for download.
proxy Set a proxy to use for downloads.
help, h Shows a list of commands or help for one command

GLOBAL OPTIONS:
--help, -h show help
--version, -v print the version
```

how to install and switch jdk. see:
- run cmd or powershell as administrator
- jvms rls *list available jdk version for download*
- jvms install 1.8.0_31 *install jdk 1.8.0_31*
- jvms ls *list installed jdk*
- jvms switch 1.8.0_31 *switch jdk version to 1.8.0_31*

![](images/powershell_2017-07-23_01-26-40.png)
---

## What's the big difference?

First and foremost, this version of jvms has no dependency on other lib. It's written in [Go](http://golang.org/), which is a much more structured
approach than hacking around a limited `.bat` file. It does not rely on having an existing jdk installation.

The control mechanism is also quite different. There are two general ways to support multiple jdk installations with hot switching capabilities.
The first is to modify the system `PATH` any time you switch versions, or bypass it by using a `.bat` file to mimic the jdk executable and redirect
accordingly. This always seemed a little hackish to me, and there are some quirks as a result of this implementation.

The second option is to use a symlink. This concept requires putting the symlink in the system `PATH`, then updating its target to
the jdk installation directory you want to use. This is a straightforward approach, and seems to be what people recommend.... until they
realize just how much of a pain symlinks are on Windows. This is why it hasn't happened before.

In order to create/modify a symlink, you must be running as an admin, and you must get around Windows UAC (that annoying prompt). As a result, JVMS for Windows
maintains a single symlink that is put in the system `PATH` during `jvms init` only. Switching to different versions of JDK is a matter of
switching the symlink target. As a result, this utility does **not** require you to run `jvms use x.x.x` every time you open a console window.
When you _do_ run `jvms use x.x.x`, the active version of jdk is automatically updated across all open console windows. It also persists
between system reboots, so you only need to use jvms when you want to make a change.

Overall, this project brings together some ideas, a few battle-hardened pieces of other modules, and support for newer versions of JDK.

I also wrote a simple [data feed](http://github.com/ystyle/jvms) containing a list of jdk versions. It's free for anyone to use.

### add a local jdk version
e.g: add the 1.7 jdk

1. copy jdk folder to jvms/store
2. rename folder to `1.7`
3. `jvms list ` check this
4. `jvms switch 1.7`
5. `java -version` check jdk verison


## Create own local download server
- create a json file. eg. `index.json`
- add you jdk download link to it. The format is like this:
```json
[
{
"version":"1.9.0",
"url":"http://192.168.1.101/files/jdk/1.9.0.zip"
}
]
```
- copy this file to a static file server like nginx, apache etc.
- run `jvms init --originalpath http://192.168.1.101/files/index.json` by the way, `jvms init --java_home` can modify default JAVA_HOME
- the run `jvms rls` or `jvms install x` will list or install your jdk version

### create a jdk zip file
- open jdk_home folder
- compression all file to `*.zip` file
- copy zip file to your server
- add this zip file link to index.json


## License

MIT.
Binary file added images/powershell_2017-07-23_00-38-13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/powershell_2017-07-23_01-26-40.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 19 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,20 @@ func commands() []cli.Command {
Action: func(c *cli.Context) error {
if c.IsSet("java_home") || config.JavaHome == "" {
config.JavaHome = c.String("java_home")
cmd := exec.Command("cmd", "/C", "setx", "JAVA_HOME", config.JavaHome, "/M")
err := cmd.Run()
if err != nil {
return errors.New("Set Environment variable `JAVA_HOME` failure: Please run as admin user")
}
fmt.Println("set `JAVA_HOME` Environment variable to ", config.JavaHome)
}
cmd := exec.Command("cmd", "/C", "setx", "JAVA_HOME", config.JavaHome, "/M")
err := cmd.Run()
if err != nil {
return errors.New("Set Environment variable `JAVA_HOME` failure: Please run as admin user")
}
fmt.Println("set `JAVA_HOME` Environment variable to ", config.JavaHome)

if c.IsSet("originalpath") || config.Originalpath == "" {
config.Originalpath = c.String("originalpath")
}
path := fmt.Sprintf(`%s/bin;%s;%s`, config.JavaHome, os.Getenv("PATH"), file.GetCurrentPath())
cmd := exec.Command("cmd", "/C", "setx", "path", path, "/m")
err := cmd.Run()
cmd = exec.Command("cmd", "/C", "setx", "path", path, "/m")
err = cmd.Run()
if err != nil {
return errors.New("Set Environment variable `PATH` failure: Please run as admin user")
}
Expand Down Expand Up @@ -148,7 +149,7 @@ func commands() []cli.Command {
os.Remove(dlzipfile)
success := web.GetJDK(config.download, v, version.Url)
if success {
fmt.Printf("Installing JDK %s...\n", v)
fmt.Printf("Installing JDK %s ...\n", v)

// Extract jdk to the temp directory
jdktempfile := fmt.Sprintf("%s%s_temp", config.download, v)
Expand Down Expand Up @@ -190,7 +191,12 @@ func commands() []cli.Command {
return errors.New("Switch jdk failed, please manually remove "+ config.JavaHome)
}
}
err := os.Symlink(config.store+v, config.JavaHome)
cmd := exec.Command("cmd", "/C", "setx", "JAVA_HOME", config.JavaHome, "/M")
err := cmd.Run()
if err != nil {
return errors.New("Set Environment variable `JAVA_HOME` failure: Please run as admin user")
}
err = os.Symlink(config.store+v, config.JavaHome)
if err != nil {
return errors.New("Switch jdk failed, " + err.Error())
}
Expand Down Expand Up @@ -294,8 +300,9 @@ func startup(c *cli.Context) error {
if err := store.Load("jvms.json", &config); err != nil {
return errors.New("failed to load the config:" + err.Error())
}
config.store = file.GetCurrentPath() + "store/"
config.download = file.GetCurrentPath() + "download/"
s := file.GetCurrentPath()
config.store = s + "store/"
config.download = s + "download/"
if config.Originalpath == "" {
config.Originalpath = default_Originalpath
}
Expand Down
6 changes: 4 additions & 2 deletions utils/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ func GetCurrentPath() string {
if err != nil {
fmt.Println(err.Error())
}
i := strings.LastIndex(s, "\\")
s = strings.Replace(s, "\\", "/", -1)
s = strings.Replace(s, "\\\\", "/", -1)
i := strings.LastIndex(s, "/")
path := string(s[0 : i+1])
return strings.Replace(path, "\\", "/", -1)
return path
}

0 comments on commit 9471acf

Please sign in to comment.