Overview
This guide covers how to build the MySQL SQL Editor application from source, run it during development, and package it as a distributable JAR file.Prerequisites
Before building, ensure you have:- Completed the development environment setup
- JDK 8 or later installed and configured
- MySQL Connector/J JAR in the
lib/directory
Compilation
Using the Command Line
Compile all Java source files from the project root directory:The
-d bin flag outputs compiled .class files to the bin/ directory, keeping them separate from source files.-cp "lib/mysql-connector-j-9.2.0.jar"- Adds the MySQL JDBC driver to the classpath-d bin- Specifies the output directory for compiled class files- Source files are listed explicitly to ensure proper compilation order
Using an IDE
- IntelliJ IDEA
- Eclipse
- VS Code
Automatic Compilation:IntelliJ IDEA compiles your code automatically as you edit:
- Ensure the MySQL JDBC driver is added to the project libraries (see Setup)
- Edit any Java file - IntelliJ will compile it automatically
- Check for errors in the Problems tool window
- Go to Build → Build Project (Ctrl+F9 / Cmd+F9)
- Or click the hammer icon in the toolbar
- Compiled classes are placed in the
out/directory by default
Running the Application
From Command Line
After compilation, run the application using thejava command:
The classpath must include both:
bin/- Your compiled application classeslib/mysql-connector-j-9.2.0.jar- The MySQL JDBC driver
- The JVM loads
com.app.Mainclass - The
mainmethod executes (seesrc/com/app/Main.java:22) - The application initializes the MVC components:
- Creates
Modelinstance for database operations - Creates
Viewinstance (login window) - Creates
SqlEditorViewinstance (SQL editor window, initially hidden) - Creates
Controllerto wire everything together
- Creates
- The login window appears, ready for database connection
From IDE
- IntelliJ IDEA
- Eclipse
- VS Code
- Open
src/com/app/Main.java - Right-click anywhere in the file
- Select Run ‘Main.main()’
- Or click the green play button in the gutter next to the
mainmethod
- Go to Run → Edit Configurations…
- Click + → Application
- Set:
- Name: MySQL SQL Editor
- Main class:
com.app.Main - VM options: (optional)
-Xmx512mfor memory settings
- Click OK
- Use the run configuration dropdown to launch the app
Packaging as JAR
Creating an Executable JAR
Package the application as a standalone JAR file that can be distributed and run anywhere:Compile the Application
First, ensure all classes are compiled (see Compilation above).
Create Manifest File
Create a manifest file that specifies the entry point and classpath:
The
Class-Path entry tells the JVM where to find the MySQL JDBC driver relative to the JAR file.Package with jar Command
Create the JAR file including all compiled classes:This creates
mysql-sql-editor.jar containing all compiled classes from the bin/ directory.Creating a Fat JAR (JAR with Dependencies)
For easier distribution, create a “fat JAR” that includes all dependencies:The fat JAR can be run with a simple
java -jar mysql-sql-editor-fat.jar command without needing external dependencies.Build Automation
For repeated builds, consider creating a build script:Troubleshooting
NoClassDefFoundError: com/mysql/cj/jdbc/Driver The MySQL JDBC driver is not in the classpath. Ensure:- The JAR is in the
lib/directory - Your classpath includes
lib/mysql-connector-j-9.2.0.jar
- The
bin/directory is in your classpath - The package structure is correct:
bin/com/app/Main.class - You’re using the fully qualified class name:
com.app.Main
- Ensure all source files are compiled together
- Check that the MySQL JDBC driver is in the compilation classpath
- Verify you’re using JDK 8 or later
Next Steps
- Learn about project dependencies
- Explore the architecture components for detailed class documentation
- Review the MVC pattern to understand the design