How to run Java programs in Sublime
Step 1: Configure Java Development Kit (JDK)
- Download and install JDK, available from the Oracle website.
- Set the JAVA_HOME environment variable to point to the JDK installation directory.
Step 2: Install the Sublime Text plug-in
- Open Sublime Text.
- Press Ctrl Shift P to open the command panel.
- Enter "Package Control: Install Package" and press Enter.
- Enter "Java Package" in the search box, find and install the Sublime plug-in.
Step 3: Create a Java Project
- Create a new file (.java) in Sublime Text.
- Copy and paste the following code into the file and save it as Main.java:
<code class="java">public class Main {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}</code>
Copy after login
Step 4: Configure compilation options
- Go to Preferences >Settings.
- In the "Additional Settings - User" section, add the following:
<code class="json">{
"java_jdk_path": "/path/to/JDK_HOME",
"java_args": ["-classpath", "${folder:.}"]
}</code>
Copy after login
- Replace "java_jdk_path" with the JDK installation directory.
Step 5: Run the Java program
- Press Ctrl B to compile and run the Java program.
- The program will output the results in the console of Sublime Text.
The above is the detailed content of How to run java program in sublime. For more information, please follow other related articles on the PHP Chinese website!