diff --git a/README.md b/README.md index 3faf6644cc2b50c867468c911a119671dc5f8fba..e2686c474caa460d2041ad6f204f821720a3c4c3 100644 --- a/README.md +++ b/README.md @@ -1,137 +1,76 @@ -
-JEnv Logo - -# Jenv: Java Environment Manager +# JEnv: Java Environment Manager ![GitHub release](https://img.shields.io/github/v/release/WhyWhatHow/jenv) ![Build Status](https://img.shields.io/github/actions/workflow/status/WhyWhatHow/jenv/release.yml?branch=main) ![Version](https://img.shields.io/badge/version-v0.6.7-blue) -**🚀 [Quick Start with Landing Page](landing-page/)** - One-click downloads with automatic platform detection (Windows/Linux/macOS) • Multi-language support (EN/中文) • Updated bi-weekly - -
- -## Recent Updates (v0.6.7) - -### 🚀 Performance Improvements -- **Ultra-fast JDK scanning**: Reduced scanning time from 3 seconds to 300ms (90% improvement) -- **Concurrent processing**: Implemented Dispatcher-Worker model with goroutines -- **Smart filtering**: Aggressive pre-filtering to skip unnecessary directories -- **Progress tracking**: Real-time scanning progress and detailed statistics - -### ✅ Cross-Platform Support -- **Linux support completed**: Full Linux compatibility with multi-shell support -- **Windows optimization**: Enhanced path validation and compatibility fixes -- **macOS preparation**: Infrastructure ready for macOS support (coming soon) +**JEnv** 是一个命令行工具,用于在系统上管理多个Java版本。它可以轻松切换不同的Java版本,添加新的Java安装,并管理Java环境。 -### 🔧 Technical Enhancements -- **Java path validation**: Improved Windows JDK detection reliability -- **Environment management**: Optimized cross-platform environment variable handling -- **Configuration cleanup**: Removed unused options and improved code maintainability +## 特性 ---- +### 高效的Java版本管理 -## Overview +- **基于符号链接的架构** + - 通过符号链接实现快速版本切换 + - 一次性系统PATH配置 + - 更改在系统重启后仍然有效 + - 所有控制台窗口即时生效 -`Jenv` is a command-line tool for managing multiple Java versions on your system. It allows you to easily switch between -different Java versions, add new Java installations, and manage your Java environment. +### 跨平台支持 -## Features +- **Windows支持** + - 基于注册表的环境变量管理(Windows标准) + - 自动管理员权限处理 + - 最小化UAC提示并遵循最小权限原则 + - 在Windows 10/11系统上性能优越 -### Efficient Java Version Management +- **Linux/Unix支持** + - 基于Shell配置文件的环境管理 + - 用户级和系统级配置选项 + - 支持多Shell环境(bash, zsh, fish) + - 智能权限处理 -- **Symlink-Based Architecture** - - Fast version switching through symbolic links - - One-time system PATH configuration - - Changes persist across system reboots - - Instant effect in all console windows +### 现代CLI体验 -### Cross-Platform Support +- **用户友好界面** + - 直观的命令结构 + - 支持亮色/暗色主题 + - 彩色输出以提高可读性 + - 详细的帮助文档 -- **Windows Support** - - Registry-based environment variable management (Windows standard) - - Automatic administrator privilege handling - - Minimized UAC prompts with least privilege principle - - Superior performance on Windows 10/11 systems +### 高级功能 -- **Linux/Unix Support** - - Shell configuration file-based environment management - - User-level and system-level configuration options - - Multi-shell environment support (bash, zsh, fish) - - Intelligent permission handling +- **智能JDK管理** + - 全系统JDK扫描 + - **使用并发Dispatcher-Worker模型将扫描性能从3秒优化到300ms** + - 基于别名的JDK管理 + - 当前JDK状态跟踪 + - 简单的JDK添加和移除 + - 详细的扫描统计和进度显示 -### Modern CLI Experience +## 安装 -- **User-Friendly Interface** - - Intuitive command structure - - Light/Dark theme support - - Colorful output for improved readability - - Detailed help documentation +### 从发布版本安装 +从[发布页面](https://github.com/WhyWhatHow/jenv/releases)下载最新版本。 -### Advanced Features +### 从源码构建 -- **Smart JDK Management** - - System-wide JDK scanning - - **Ultra-fast scanning performance (3s → 300ms)** using concurrent Dispatcher-Worker model - - Alias-based JDK management - - Current JDK status tracking - - Easy JDK addition and removal - - Detailed scanning statistics and progress display +#### 先决条件 -### Future-Ready - -- **Cross-Platform Support** - - Windows support (✅ Complete) - - Linux support (✅ Complete) - - macOS support (🚧 In Progress) -## Project Structure - -``` -. -├── src/ # Source code directory -│ ├── cmd/ # Command implementations -│ │ ├── add.go # Add JDK command -│ │ ├── list.go # List JDKs command -│ │ ├── remove.go # Remove JDK command -│ │ ├── use.go # Switch JDK command -│ │ └── root.go # Root command and flags -│ ├── internal/ # Internal packages -│ │ ├── config/ # Configuration management -│ │ ├── constants/ # Constants definitions -│ │ ├── env/ # Environment handling -│ │ ├── java/ # Java SDK management -│ │ ├── logging/ # Logging utilities -│ │ ├── style/ # UI styling -│ │ └── sys/ # System utilities -│ └── jenv.go # Main entry point -├── doc/ # Documentation -└── .github/ # GitHub configurations - └── workflows/ # CI/CD workflows -``` - -## Installation - -### From Release -Download the latest release from the [Releases page](https://github.com/WhyWhatHow/jenv/releases). - -### Build from Source - -#### Prerequisites - -- Go 1.21 or higher +- Go 1.21 或更高版本 - Git -- **Windows**: Administrator privileges required for system symbolic links -- **Linux**: Root privileges recommended for system-wide installation (optional) +- **Windows**: 需要管理员权限以创建系统符号链接 +- **Linux**: 推荐root权限用于系统范围安装(可选) -#### Build Steps +#### 构建步骤 -1. Clone the repository: +1. 克隆仓库: ```bash git clone https://github.com/WhyWhatHow/jenv.git cd jenv ``` -2. Build the project: +2. 构建项目: ```bash cd src @@ -146,78 +85,74 @@ go build -ldflags "-X github.com/whywhathow/jenv/cmd.Version=1.0.0" -o jenv go build -o jenv ``` -## Usage - -![jenv.gif](assets/jenv.gif) +## 使用方法 -### Installation Verification +### 安装验证 ```bash -# Verify jenv installation +# 验证jenv安装 jenv --version ``` -### First-time Setup +### 首次设置 ```bash -# Initialize jenv (required for first-time use) +# 初始化jenv(首次使用必需) jenv init -# Add jenv to your system PATH +# 将jenv添加到系统PATH jenv add-to-path ``` -**Note for Linux users**: After initialization, you may need to restart your shell or run: +**Linux用户注意事项**: 初始化后,您可能需要重启shell或运行: ```bash -# For bash users +# 对于bash用户 source ~/.bashrc -# For zsh users +# 对于zsh用户 source ~/.zshrc -# For fish users +# 对于fish用户 source ~/.config/fish/config.fish ``` -### Add and remove JDK - -![jenv-add.gif](assets/jenv-add.gif) +### 添加和移除JDK ```bash -# Add a new JDK with an alias name +# 添加具有别名的新JDK #jenv add jenv add jdk8 "C:\Program Files\Java\jdk1.8.0_291" #jenv remove jenv remove jdk8 ``` -### List all installed JDKs +### 列出所有已安装的JDK ```bash jenv list ``` -### Switch to a specific JDK version +### 切换到特定的JDK版本 ```bash #jenv use jenv use jdk8 ``` -### Remove a JDK from jenv +### 从jenv中移除JDK ```bash #jenv remove jenv remove jdk8 ``` -### Show current JDK in use +### 显示当前使用的JDK ```bash jenv current ``` -### Scan system for installed JDKs +### 扫描系统中的JDK ```bash # Windows jenv scan c:\ @@ -229,108 +164,102 @@ jenv scan /opt # macOS jenv scan /Library/Java/JavaVirtualMachines -# Performance: Ultra-fast scanning with concurrent processing -# 🚀 Optimized from 3 seconds to 300ms using Dispatcher-Worker model +# 性能: 使用并发处理实现超快速扫描 +# 🚀 使用Dispatcher-Worker模型将性能从3秒优化到300ms ``` -### Add jenv to system PATH +### 将jenv添加到系统PATH ```bash jenv add-to-path ``` -### Change UI theme (light/dark) +### 更改UI主题(亮色/暗色) ```bash #jenv theme jenv theme dark ``` -### help & version +### 帮助与版本 ```bash #jenv help [command] jenv --version ``` -## Q&A - -### Why are administrator privileges needed? +## 常见问题 -**Windows**: Due to Windows system restrictions, creating system-level symbolic links requires running PowerShell as Administrator. +### 为什么需要管理员权限? -**Linux**: Administrator privileges (sudo/root) are only required for: -- System-wide installation (symlinks in `/opt/jenv/`) -- Modifying system-level environment files (`/etc/environment`) +**Windows**: 由于Windows系统限制,创建系统级符号链接需要以管理员身份运行PowerShell。 -Without root privileges, jenv will automatically use user-level configuration in your home directory. +**Linux**: 仅在以下情况下需要管理员权限(sudo/root): +- 系统范围安装(在`/opt/jenv/`中创建符号链接) +- 修改系统级环境文件(`/etc/environment`) -### Why was this project created? +如果没有root权限,jenv将自动在您的主目录中使用用户级配置。 -While Linux and macOS users have mature tools like `sdkman` and `jenv` for Java version management, Windows users have -limited options. The existing [Jenv-forWindows](https://github.com/FelixSelter/JEnv-for-Windows) solution, while -functional, faces performance issues on Windows 10 systems. +### 为什么创建这个项目? -This project was born out of two motivations: +虽然Linux和macOS用户有成熟的工具如`sdkman`和`jenv`用于Java版本管理,但Windows用户的选项有限。现有的[Jenv-forWindows](https://github.com/FelixSelter/JEnv-for-Windows)解决方案虽然功能正常,但在Windows 10系统上面临性能问题。 -1. To create a fast, efficient Java version manager specifically optimized for Windows -2. To explore AI-assisted development using tools like `cursor` and `Trae` while learning Go programming from scratch +这个项目出于两个动机而诞生: -The goal is to provide Windows developers with a robust, performant solution for managing multiple Java environments, -similar to what Linux and macOS users already enjoy. +1. 创建一个快速、高效的Java版本管理器,特别优化了Windows环境 +2. 使用像`cursor`和`Trae`这样的工具探索AI辅助开发,同时从零开始学习Go编程 -### How it works? +目标是为Windows开发人员提供一个强大、高效的Java环境管理解决方案,类似于Linux和macOS用户已经享受的解决方案。 -Inspired by nvm-windows, JEnv uses symlinks for Java version management across all platforms, which offers several advantages: +### 它是如何工作的? -1. **Symlink-Based Architecture** - - **Windows**: Creates a single symlink at `C:\java\JAVA_HOME` during installation - - **Linux**: Creates symlink at `/opt/jenv/java_home` (system) or `~/.jenv/java_home` (user) - - Switching Java versions only requires updating the symlink target - - No need to modify system PATH repeatedly - - Changes persist across system reboots and apply to all console windows/shells +受nvm-windows启发,JEnv在所有平台上使用符号链接进行Java版本管理,这提供了几个优势: -2. **High-Performance Implementation** - - **Ultra-fast JDK scanning**: Optimized from 3 seconds to 300ms using concurrent processing - - **Dispatcher-Worker Model**: Parallel JDK detection with worker goroutines - - **Intelligent Pre-filtering**: Aggressive directory filtering to skip unnecessary locations - - **Detailed Statistics**: Real-time progress tracking and comprehensive scan results - - **Optimized Path Exclusion**: Smart logic to avoid scanning duplicate or invalid paths +1. **基于符号链接的架构** + - **Windows**: 在安装期间在`C:\java\JAVA_HOME`创建单个符号链接 + - **Linux**: 在系统(`/opt/jenv/java_home`)或用户(`~/.jenv/java_home`)级别创建符号链接 + - 切换Java版本只需更新符号链接目标 + - 不需要反复修改系统PATH + - 更改在系统重启后仍然有效,并适用于所有控制台窗口/Shell -3. **Implementation Details** - - During initialization: - - **Windows**: Creates `JAVA_HOME` directory at `C:\java\JAVA_HOME` - - **Linux**: Creates symlink directory based on privileges (system or user level) - - Adds `JAVA_HOME/bin` to system PATH (one-time setup) - - Creates initial symlink to default JDK - - When switching versions: - - Simply updates symlink target to desired JDK - - No PATH modifications needed - - Changes take effect immediately in all console windows/shells +2. **高性能实现** + - **超快速JDK扫描**: 使用并发处理从3秒优化到300ms + - **Dispatcher-Worker模型**: 使用工作goroutine并行JDK检测 + - **智能预过滤**: 激进的目录过滤以跳过不必要的位置 + - **详细的统计信息**: 实时进度跟踪和全面的扫描结果 + - **优化的路径排除**: 智能逻辑以避免扫描重复或无效的路径 -4. **Permission Handling** - - **Windows**: Administrator privileges required for system symbolic links - - **Linux**: Root privileges optional - falls back to user-level configuration - - UAC/sudo prompts handled automatically with minimal privilege scope - - Follows the principle of least privilege - - Permission requests only occur during initialization and version switching +3. **实现细节** + - 在初始化期间: + - **Windows**: 在`C:\java\JAVA_HOME`创建JAVA_HOME目录 + - **Linux**: 根据权限创建系统或用户级别的符号链接目录 + - 将`JAVA_HOME/bin`添加到系统PATH(一次性设置) + - 创建指向默认JDK的初始符号链接 + - 在切换版本时: + - 仅需更新符号链接目标到所需的JDK + - 不需要修改PATH + - 更改立即在所有控制台窗口/Shell中生效 -5. **Multi-Shell Support (Linux)** - - Automatically detects and configures bash, zsh, fish shells - - Updates appropriate configuration files (.bashrc, .zshrc, config.fish) - - Ensures environment variables persist across shell sessions +4. **权限处理** + - **Windows**: 需要管理员权限以创建系统符号链接 + - **Linux**: root权限可选 - 回退到用户级配置 + - UAC/sudo提示自动处理并遵循最小权限范围 + - 遵循最小权限原则 + - 仅在初始化和版本切换时发生权限请求 -This approach is more efficient than constantly modifying system PATH variables, providing a cleaner and more reliable -solution for Java version management across all supported platforms. +5. **多Shell支持(Linux)** + - 自动检测和配置bash、zsh、fish shell + - 更新适当的配置文件(.bashrc、.zshrc、config.fish) + - 确保环境变量在shell会话之间持续存在 -## Acknowledgments +这种方法比不断修改系统PATH变量更高效,为所有支持的平台提供更清洁和可靠的Java版本管理解决方案。 -- [cobra](https://github.com/spf13/cobra) - A powerful CLI framework for Go -- [jreleaser](https://jreleaser.org/) - A release automation tool -- [nvm-windows](https://github.com/coreybutler/nvm-windows) - Inspired our symlink-based approach -- [Jenv-for-Windows](https://github.com/FelixSelter/JEnv-for-Windows) - A predecessor project for Java version - management on Windows +## 致谢 -## License +- [cobra](https://github.com/spf13/cobra) - 一个强大的Go语言CLI框架 +- [jreleaser](https://jreleaser.org/) - 一个发布自动化工具 +- [nvm-windows](https://github.com/coreybutler/nvm-windows) - 启发了我们的符号链接方法 +- [Jenv-for-Windows](https://github.com/FelixSelter/JEnv-for-Windows) - 一个用于Windows的Java版本管理的前身项目 -This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details. +## 许可证 +本项目采用Apache许可证2.0版 - 请参阅[LICENSE](LICENSE)文件了解详细信息。 \ No newline at end of file