Skip to main content

Maven Build System

MatriculaUniPoo uses Apache Maven for build automation and dependency management. The project configuration is defined in pom.xml.

Project Configuration

The pom.xml file defines the project structure and dependencies:
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
         http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany.matricula</groupId>
    <artifactId>Matricula</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    
    <dependencies>
        <dependency>
            <groupId>org.netbeans.external</groupId>
            <artifactId>AbsoluteLayout</artifactId>
            <version>RELEASE190</version>
            <type>jar</type>
        </dependency>
    </dependencies>
    
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>20</maven.compiler.source>
        <maven.compiler.target>20</maven.compiler.target>
        <exec.mainClass>com.mycompany.matricula.Matricula</exec.mainClass>
    </properties>
</project>
The project is configured for Java 20 and uses UTF-8 encoding for all source files.

Build Commands

Basic Build Lifecycle

1

Clean

Remove all generated files from previous builds:
mvn clean
This deletes the target/ directory and all compiled classes.
2

Compile

Compile the source code:
mvn compile
Compiles all .java files to .class files in target/classes/.
3

Test

Run unit tests (if available):
mvn test
Currently, the project doesn’t include unit tests. This phase will be skipped.
4

Package

Create the JAR file:
mvn package
Produces target/Matricula-1.0-SNAPSHOT.jar
5

Install

Install to local Maven repository:
mvn install
Installs the artifact to ~/.m2/repository/

Common Build Commands

# Clean and compile from scratch
mvn clean compile

Running the Application

Using Maven Exec Plugin

Run the application directly with Maven:
mvn clean compile exec:java
Note that exec.mainClass in pom.xml is set to com.mycompany.matricula.Matricula, but the actual main class is logica.Main. You may need to update this:
mvn exec:java -Dexec.mainClass="logica.Main"

Running the JAR File

After packaging, run the JAR directly:
# First, package the application
mvn clean package

# Then run the JAR
java -cp target/Matricula-1.0-SNAPSHOT.jar logica.Main

Project Structure

Understanding the build output structure:
Matricula/
├── pom.xml                          # Maven configuration
├── src/
│   └── main/
│       └── java/
│           ├── igu/                 # GUI package (interface gráfica de usuario)
│           │   ├── Inicio.java      # Welcome screen
│           │   ├── Login.java       # Login screen
│           │   ├── Matricula.java   # Course enrollment screen
│           │   ├── Registrar.java   # Student registration screen
│           │   ├── Inicio.form      # NetBeans form definition
│           │   ├── Login.form
│           │   ├── Matricula.form
│           │   └── Registrar.form
│           └── logica/              # Business logic package
│               ├── Alumno.java      # Student model
│               ├── Cursos.java      # Course model
│               └── Main.java        # Application entry point
└── target/                          # Build output (generated)
    ├── classes/                     # Compiled .class files
    │   ├── igu/
    │   └── logica/
    ├── generated-sources/           # Generated code (if any)
    ├── maven-archiver/              # Maven metadata
    ├── maven-status/                # Build status
    └── Matricula-1.0-SNAPSHOT.jar   # Packaged application

Understanding the Packages

GUI Package (igu)

Contains all Swing-based user interface components:
The first screen users see when launching the application.
Inicio.java:6-12
public class Inicio extends javax.swing.JFrame {
    private Registrar registrate;

    public Inicio() {
        initComponents();
        this.registrate = new Registrar();
        registrate.setIni(this);
    }
}
Displays welcome message and registration button.
Handles new student registration with input validation.
Registrar.java:207-227
private void btnRegistrarseActionPerformed(java.awt.event.ActionEvent evt) {
    String nombre = txtNombre.getText();
    String apellido = txtApellido.getText();
    String dni = txtDni.getText();
    String contra = txtContra.getText();
    
    if (nombre.isEmpty()) {
        JOptionPane.showMessageDialog(this, "COMPLETE SU NOMBRE", 
            "Advertencia", JOptionPane.WARNING_MESSAGE);
    } else if (apellido.isEmpty()) {
        JOptionPane.showMessageDialog(this, "COMPLETE SU APELLIDO", 
            "Advertencia", JOptionPane.WARNING_MESSAGE);
    } else if (dni.isEmpty()) {
        JOptionPane.showMessageDialog(this, "COMPLETE SU DNI", 
            "Advertencia", JOptionPane.WARNING_MESSAGE);
    } else if (contra.isEmpty()) {
        JOptionPane.showMessageDialog(this, "COMPLETE SU CONTRASEÑA", 
            "Advertencia", JOptionPane.WARNING_MESSAGE);
    } else {
        JOptionPane.showMessageDialog(null, "REGISTRO EXITOSO");
        // Continue to login...
    }
}
Validates user credentials against registered information.
Login.java:171-183
private void btnIniciarSesionActionPerformed(java.awt.event.ActionEvent evt) {
    String usuario = txtUsuario.getText();
    String contra = new String(pswContra.getPassword());
    
    if (usuario.equals(regisDni) && contra.equals(regisContra)) {
        JOptionPane.showMessageDialog(null, "INICIO EXITOSO");
        matri.setLog(this);
        matri.setVisible(true);
        matri.setLocationRelativeTo(null);
        this.setVisible(false);
    } else {
        JOptionPane.showMessageDialog(this, 
            "USUARIO O CONTRASEÑA INCORRECTA", "Error", JOptionPane.ERROR_MESSAGE);
    }
}
Main application screen for selecting and enrolling in courses.
Matricula.java:413-422
private void btnMatematicasActionPerformed(java.awt.event.ActionEvent evt) {
    Cursos curso = new Cursos();
    curso.setMatematica(scrMatematica.getSelectedItem().toString());
    curso.setHistoria(scrHistoria.getSelectedItem().toString());
    curso.setLiteratura(scrLiteratura.getSelectedItem().toString());
    curso.setCivica(scrCivica.getSelectedItem().toString());
    curso.setCiencias(scrCiencias.getSelectedItem().toString());
    listaCursos.add(curso);
    refrescarTabla();
}
Manages course selection using JComboBox components and displays enrolled courses in a JTable.

Logic Package (logica)

Contains business logic and data models:
JavaBean representing a student with properties:
Alumno.java:4-15
public class Alumno {
    private String nombre, apellido, contraseña, dni;
    
    public Alumno() {}

    public Alumno(String nombre, String apellido, String contraseña, String dni) {
        this.nombre = nombre;
        this.apellido = apellido;
        this.contraseña = contraseña;
        this.dni = dni;
    }
    // Getters and setters...
}
Includes standard getters and setters for all properties.
Represents a collection of enrolled courses:
Cursos.java:4-16
public class Cursos {
    String matematica, historia, ciencias, literatura, civica;
    
    public Cursos() {}
    
    public Cursos(String matematica, String historia, String ciencias, 
                  String literatura, String civica) {
        this.matematica = matematica;
        this.historia = historia;
        this.ciencias = ciencias;
        this.literatura = literatura;
        this.civica = civica;
    }
    // Getters and setters...
}
Stores course selections as formatted strings containing professor, room, and schedule information.
Application launcher:
Main.java:6-12
public class Main {
    public static void main(String[] args) {
        Inicio in = new Inicio();
        in.setVisible(true);
        in.setLocationRelativeTo(null);
    }
}
Creates and displays the welcome screen centered on the display.

Creating an Executable JAR

To create a JAR with all dependencies included (fat JAR), add the Maven Assembly Plugin:
1

Update pom.xml

Add the assembly plugin configuration:
pom.xml
<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.6.0</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>logica.Main</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
2

Build the Fat JAR

mvn clean package
This creates two JAR files:
  • Matricula-1.0-SNAPSHOT.jar - Standard JAR
  • Matricula-1.0-SNAPSHOT-jar-with-dependencies.jar - Executable fat JAR
3

Run the Executable JAR

java -jar target/Matricula-1.0-SNAPSHOT-jar-with-dependencies.jar
This can be distributed as a single file with all dependencies included.

Build Optimization

Parallel Builds

Speed up compilation using multiple threads:
mvn clean package -T 4
Use -T 1C for one thread per CPU core.

Dependency Caching

Maven caches dependencies in ~/.m2/repository/. To update dependencies:
# Update all dependencies
mvn clean install -U

# View dependency tree
mvn dependency:tree

Compiler Options

Add compiler arguments for optimization:
pom.xml
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.11.0</version>
    <configuration>
        <source>20</source>
        <target>20</target>
        <compilerArgs>
            <arg>-Xlint:all</arg>
            <arg>-Xlint:-processing</arg>
        </compilerArgs>
    </configuration>
</plugin>

Continuous Integration

GitHub Actions Example

Create .github/workflows/build.yml:
build.yml
name: Java CI with Maven

on:
  push:
    branches: [ main, develop ]
  pull_request:
    branches: [ main ]

jobs:
  build:
    runs-on: ubuntu-latest
    
    steps:
    - uses: actions/checkout@v4
    
    - name: Set up JDK 20
      uses: actions/setup-java@v4
      with:
        java-version: '20'
        distribution: 'temurin'
        cache: maven
    
    - name: Build with Maven
      run: mvn clean package -B
    
    - name: Upload JAR
      uses: actions/upload-artifact@v3
      with:
        name: Matricula-JAR
        path: target/*.jar

Troubleshooting Build Issues

Problem: Source code fails to compileSolutions:
# Verify Java version
java -version
mvn -version

# Clean and rebuild
mvn clean
rm -rf target/
mvn compile

# Check for syntax errors
mvn compile -X  # verbose output
Problem: Cannot download AbsoluteLayout dependencySolutions:
# Force update dependencies
mvn clean install -U

# Clear local repository cache
rm -rf ~/.m2/repository/org/netbeans/external/AbsoluteLayout
mvn clean install

# Use Maven Central mirror if needed
# Add to ~/.m2/settings.xml
Problem: Build fails with OutOfMemoryErrorSolution: Increase Maven memory:
export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=256m"
mvn clean package
Problem: NetBeans .form files not being processedNote: .form files are NetBeans-specific GUI designer files. They are not compiled directly but are used by NetBeans IDE to generate the corresponding Java code (the initComponents() method).If you’re not using NetBeans, the Java files already contain the generated code and will compile correctly.

Next Steps

Development Setup

Configure your development environment

Contributing Guidelines

Learn how to contribute to the project

Build docs developers (and LLMs) love