Skip to content

elix545/Java_Txt_Project_Space

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

Java Text Project Space

This repository contains a Java console application and environment setup scripts for Java development.

Project Structure

Java_Txt_Project_Space/
├── LICENSE
├── README.md
└── Test_Console/
    ├── Test_Console.java           # Main Java application
    ├── Test_Console.class          # Compiled Java bytecode
    ├── Test_Console.mf             # Manifest file for JAR creation
    ├── SetEnviromentVar.ps1        # PowerShell environment setup script
    ├── SetEnviromentVar.bat        # Batch environment setup script
    ├── ExecuteTestConsole.ps1      # PowerShell execution script
    └── ExecuteTestConsole.bat      # Batch execution script

Java Application

Test_Console.java

A simple Java console application that:

  • Prints "Hola Mundo" (Hello World)
  • Reads user input from console
  • Demonstrates basic Java I/O operations

Environment Setup Scripts

SetEnviromentVar.ps1 (PowerShell)

PowerShell script to configure Java environment variables for development with automatic Java version detection and selection.

Usage:

# Set execution policy (if needed)
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

# Run with default Java version (jdk1.6.0_45)
.\SetEnviromentVar.ps1

# Run with specific Java version
.\SetEnviromentVar.ps1 -JavaVersion jdk-11
.\SetEnviromentVar.ps1 -JavaVersion jdk-17

SetEnviromentVar.bat (Batch)

Windows batch script to configure Java environment variables for development with automatic Java version detection and selection.

Usage:

# Run as administrator (recommended) with default Java version (jdk1.6.0_45)
SetEnviromentVar.bat

# Run with specific Java version
SetEnviromentVar.bat -java jdk-11
SetEnviromentVar.bat -java jdk-17

Execution Scripts

ExecuteTestConsole.ps1 (PowerShell)

PowerShell script to automatically compile and execute the Test_Console Java application with different execution modes.

Note: Run from the Test_Console folder, or use .\Test_Console\ExecuteTestConsole.ps1 from the project root.

Usage:

cd Test_Console
# Execute with default mode (class files) and default Java version (jdk1.6.0_45)
.\ExecuteTestConsole.ps1

# Execute with specific mode
.\ExecuteTestConsole.ps1 -ExecutionMode jar
.\ExecuteTestConsole.ps1 -ExecutionMode class-package
.\ExecuteTestConsole.ps1 -ExecutionMode jar-package

# Execute with specific Java version
.\ExecuteTestConsole.ps1 -JavaVersion jdk-11
.\ExecuteTestConsole.ps1 -JavaVersion jdk-17

# Combine execution mode and Java version
.\ExecuteTestConsole.ps1 -ExecutionMode source -JavaVersion jdk-17
.\ExecuteTestConsole.ps1 -ExecutionMode jar -JavaVersion jdk-11
.\ExecuteTestConsole.ps1 -ExecutionMode jshell -JavaVersion jdk-17

Available execution modes:

  • source: Execute directly from source code (Java 11+)
  • class (default): Compile and run with *.class files
  • class-package: Compile and run with *.class files and package
  • jar: Compile, create JAR, and run with *.jar files
  • jar-package: Compile, create JAR with package, and run
  • jshell: Launch JShell interactive REPL (Java 9+)

ExecuteTestConsole.bat (Batch)

Windows batch script to automatically compile and execute the Test_Console Java application with different execution modes.

Note: Run from the Test_Console folder, or use Test_Console\ExecuteTestConsole.bat from the project root.

Usage:

cd Test_Console
# Execute with default mode (class files) and default Java version (jdk1.6.0_45)
ExecuteTestConsole.bat

# Execute with specific mode
ExecuteTestConsole.bat -source
ExecuteTestConsole.bat -jar
ExecuteTestConsole.bat -jshell
ExecuteTestConsole.bat -class-package
ExecuteTestConsole.bat -jar-package

# Execute with specific Java version
ExecuteTestConsole.bat -java jdk-11
ExecuteTestConsole.bat -java jdk-17

# Combine execution mode and Java version
ExecuteTestConsole.bat -source -java jdk-17
ExecuteTestConsole.bat -jar -java jdk-11
ExecuteTestConsole.bat -jshell -java jdk-17

Available execution modes:

  • -source: Execute directly from source code (Java 11+)
  • -class (default): Compile and run with *.class files
  • -class-package: Compile and run with *.class files and package
  • -jar: Compile, create JAR, and run with *.jar files
  • -jar-package: Compile, create JAR with package, and run
  • -jshell: Launch JShell interactive REPL (Java 9+)

Java Version Selection

All scripts now support automatic Java version detection and selection from C:\Program Files\Java.

Features:

  • Automatic Detection: Scans C:\Program Files\Java for available JDK/JRE installations
  • Default Version: Uses jdk1.6.0_45 as default (configurable)
  • Version Display: Shows all available Java versions with the selected one highlighted
  • Fallback: If specified version not found, uses first available version
  • Cross-Platform: Works with any Java version naming convention (jdk-11, jdk-17, jdk1.8.0_XXX, etc.)

SetEnviromentVar Scripts Parameters:

  • PowerShell: -JavaVersion (e.g., jdk-11, jdk-17, jdk1.8.0_XXX)
  • Batch: -java (e.g., jdk-11, jdk-17, jdk1.8.0_XXX)

ExecuteTestConsole Scripts Parameters:

  • PowerShell: -JavaVersion (e.g., jdk-11, jdk-17, jdk1.8.0_XXX)
  • Batch: -java (e.g., jdk-11, jdk-17, jdk1.8.0_XXX)

Examples:

Environment Setup:

# Set environment with default Java version
.\SetEnviromentVar.ps1

# Set environment with Java 11
.\SetEnviromentVar.ps1 -JavaVersion jdk-11
# Set environment with default Java version
SetEnviromentVar.bat

# Set environment with Java 11
SetEnviromentVar.bat -java jdk-11

Application Execution:

# Use Java 11
.\ExecuteTestConsole.ps1 -JavaVersion jdk-11

# Use Java 17 with source execution
.\ExecuteTestConsole.ps1 -ExecutionMode source -JavaVersion jdk-17
# Use Java 11
ExecuteTestConsole.bat -java jdk-11

# Use Java 17 with source execution
ExecuteTestConsole.bat -source -java jdk-17

Environment Variables Configured

Both scripts set the following environment variables:

  • JAVA_HOME: C:\Program Files\Java\jdk1.6.0_45
  • PATH: Adds %JAVA_HOME%\bin to system PATH
  • CLASSPATH: Set to . (current directory)

Important Development Notes

Environment Variable Configuration

CLASSPATH=.;+ n values; or CLASSPATH=.;+ n values; + package;
PATH=C:\Program Files\Java\jdk1.6.0_45\bin;+ n values;
JAVA_HOME=C:\Program Files\Java\jdk1.6.0_45;

Compilation and Execution

JShell execution (Java 9+):

# Launch JShell interactive REPL
jshell
# Use /help for commands, /exit to quit

Direct source execution (Java 11+):

# Run directly from source without compilation
java Test_Console.java

With *.class files:

# Compile
javac -g -cp . Test_Console.java

# Run
java Test_Console
java -cp . Test_Console

With *.class files and package:

# Compile
javac -g -cp . Test_Console.java

# Run (from parent directory)
cd ..
java Test_Console.Test_Console

With *.jar files:

# Compile
javac -g -cp . Test_Console.java

# Create JAR
jar -cmf Test_Console.mf Test_Console.jar Test_Console.class

# Run
java -jar Test_Console.jar

With *.jar files and package:

# Compile
javac -g -cp . Test_Console.java

# Create JAR (from parent directory)
cd ..
jar -cmf Test_Console\Test_Console.mf Test_Console.jar Test_Console\*.class

# Run
java -jar Test_Console.jar

Manifest File (Test_Console.mf)

Main-Class: Test_Console

Note: Each line ends with CR+LF character on Windows OS

Important: The manifest file is configured for the current state where the package declaration is commented out. If you uncomment the package declaration in Test_Console.java, you would need to change the manifest to Main-Class: Test_Console.Test_Console.

Package Structure

When using packages, the main class and main file names must be the same for both object and source files.

Requirements

  • Java Development Kit (JDK) 1.6.0_45 or compatible version
  • Windows operating system
  • PowerShell (for .ps1 script) or Command Prompt (for .bat script)

Installation

  1. Clone or download this repository
  2. Run the appropriate environment setup script:
    • For PowerShell: SetEnviromentVar.ps1
    • For Batch: SetEnviromentVar.bat
  3. Restart your terminal or IDE for environment changes to take effect
  4. Use the execution scripts (from the Test_Console folder) to compile and run the Java application:
    • For PowerShell: cd Test_Console then .\ExecuteTestConsole.ps1
    • For Batch: cd Test_Console then ExecuteTestConsole.bat

Quick Start

  1. Setup Environment:

    # Run as administrator with default Java version (jdk1.6.0_45)
    SetEnviromentVar.bat
    
    # Or setup with specific Java version
    SetEnviromentVar.bat -java jdk-11
  2. Execute Application:

    cd Test_Console
    # Execute directly from source (Java 11+)
    ExecuteTestConsole.bat -source
    
    # Simple execution with class files (default Java version)
    ExecuteTestConsole.bat
    
    # Or create and run JAR file
    ExecuteTestConsole.bat -jar
    
    # Use specific Java version
    ExecuteTestConsole.bat -java jdk-11
    ExecuteTestConsole.bat -source -java jdk-17
    ExecuteTestConsole.bat -jshell -java jdk-17

Notes

  • The environment setup scripts require administrator privileges to modify system environment variables
  • After running the setup scripts, you may need to restart your development environment
  • The scripts are configured for JDK 1.6.0_45 - modify the paths if using a different Java version
  • CATALINA_HOME is included as a commented option for Tomcat development (uncomment if needed)
  • The execution scripts automatically handle compilation and provide multiple execution modes
  • All scripts include error checking and informative output messages
  • Source execution mode requires Java 11 or higher; older versions will fall back to compilation mode
  • JShell mode requires Java 9 or higher; use -ExecutionMode jshell (PowerShell) or -jshell (Batch) with a JDK 9+ (e.g. jdk-11, jdk-17)

License

This project is licensed under the MIT License - see the LICENSE file for details.

MIT License Summary

  • ✅ Commercial use allowed
  • ✅ Modification allowed
  • ✅ Distribution allowed
  • ✅ Private use allowed
  • ❌ No liability or warranty provided

About

Java_Txt_Project_Space

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors