Skip to main content

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:

Compilation

Using the Command Line

Compile all Java source files from the project root directory:
# Create output directory for compiled classes
mkdir -p bin

# Compile all Java files with MySQL JDBC driver in classpath
javac -cp "lib/mysql-connector-j-9.2.0.jar" -d bin \
  src/com/app/Main.java \
  src/com/app/Model/Model.java \
  src/com/app/View/View.java \
  src/com/app/View/SqlEditorView.java \
  src/com/app/Controller/Controller.java
The -d bin flag outputs compiled .class files to the bin/ directory, keeping them separate from source files.
Compilation Flags Explained:
  • -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
On Windows, use semicolons (;) as the classpath separator if you need to include multiple JARs:
javac -cp "lib/mysql-connector-j-9.2.0.jar;other.jar" -d bin ...
On Linux/macOS, use colons (:).

Using an IDE

Automatic Compilation:IntelliJ IDEA compiles your code automatically as you edit:
  1. Ensure the MySQL JDBC driver is added to the project libraries (see Setup)
  2. Edit any Java file - IntelliJ will compile it automatically
  3. Check for errors in the Problems tool window
Manual Build:To manually trigger a build:
  1. Go to Build → Build Project (Ctrl+F9 / Cmd+F9)
  2. Or click the hammer icon in the toolbar
  3. Compiled classes are placed in the out/ directory by default

Running the Application

From Command Line

After compilation, run the application using the java command:
# Run from the project root
java -cp "bin:lib/mysql-connector-j-9.2.0.jar" com.app.Main
The classpath must include both:
  • bin/ - Your compiled application classes
  • lib/mysql-connector-j-9.2.0.jar - The MySQL JDBC driver
What happens when you run:
  1. The JVM loads com.app.Main class
  2. The main method executes (see src/com/app/Main.java:22)
  3. The application initializes the MVC components:
    • Creates Model instance for database operations
    • Creates View instance (login window)
    • Creates SqlEditorView instance (SQL editor window, initially hidden)
    • Creates Controller to wire everything together
  4. The login window appears, ready for database connection

From IDE

  1. Open src/com/app/Main.java
  2. Right-click anywhere in the file
  3. Select Run ‘Main.main()’
  4. Or click the green play button in the gutter next to the main method
Create a Run Configuration:For repeated runs with custom settings:
  1. Go to Run → Edit Configurations…
  2. Click +Application
  3. Set:
    • Name: MySQL SQL Editor
    • Main class: com.app.Main
    • VM options: (optional) -Xmx512m for memory settings
  4. Click OK
  5. 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:
1

Compile the Application

First, ensure all classes are compiled (see Compilation above).
2

Create Manifest File

Create a manifest file that specifies the entry point and classpath:
# Create MANIFEST.MF
cat > MANIFEST.MF << EOF
Manifest-Version: 1.0
Main-Class: com.app.Main
Class-Path: mysql-connector-j-9.2.0.jar
EOF
The Class-Path entry tells the JVM where to find the MySQL JDBC driver relative to the JAR file.
3

Package with jar Command

Create the JAR file including all compiled classes:
# Create JAR with manifest
jar cfm mysql-sql-editor.jar MANIFEST.MF -C bin .
This creates mysql-sql-editor.jar containing all compiled classes from the bin/ directory.
4

Run the JAR

Run the packaged application:
# Ensure mysql-connector-j-9.2.0.jar is in the same directory
java -jar mysql-sql-editor.jar
The MySQL JDBC driver JAR (mysql-connector-j-9.2.0.jar) must be in the same directory as your application JAR, or you must specify its location with -cp.

Creating a Fat JAR (JAR with Dependencies)

For easier distribution, create a “fat JAR” that includes all dependencies:
# Extract MySQL JDBC driver classes
mkdir -p temp
cd temp
jar xf ../lib/mysql-connector-j-9.2.0.jar
cd ..

# Copy compiled classes
cp -r bin/* temp/

# Create fat JAR
jar cfe mysql-sql-editor-fat.jar com.app.Main -C temp .

# Clean up
rm -rf temp
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:
#!/bin/bash
set -e

echo "Cleaning previous build..."
rm -rf bin
mkdir -p bin

echo "Compiling Java sources..."
javac -cp "lib/mysql-connector-j-9.2.0.jar" -d bin \
  src/com/app/Main.java \
  src/com/app/Model/Model.java \
  src/com/app/View/View.java \
  src/com/app/View/SqlEditorView.java \
  src/com/app/Controller/Controller.java

echo "Build successful!"
echo "Run with: java -cp \"bin:lib/mysql-connector-j-9.2.0.jar\" com.app.Main"
Make the script executable and run it:
# Linux/macOS
chmod +x build.sh
./build.sh

# Windows
build.bat

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
Error: Could not find or load main class com.app.Main Check that:
  • 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
Compilation errors about missing symbols
  • 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

Build docs developers (and LLMs) love