Practical Examples
Scenario 1: Basic Executable JAR
Project Structure
mkdir -p /home/labex/manifest-demo/src/main/java/com/labex
cd /home/labex/manifest-demo
Create Main Application
// src/main/java/com/labex/MainApplication.java
package com.labex;
public class MainApplication {
public static void main(String[] args) {
System.out.println("LabEx Manifest Demo");
}
}
Compile and Package
## Compile Java files
javac src/main/java/com/labex/MainApplication.java
## Create manifest file
mkdir -p META-INF
echo "Main-Class: com.labex.MainApplication" > META-INF/MANIFEST.MF
## Create JAR with manifest
jar cvfm app.jar META-INF/MANIFEST.MF -C src/main/java .
Scenario 2: Dependency Management
Manifest with External Dependencies
graph LR
A[Manifest] --> B[Main-Class]
A --> C[Class-Path]
C --> D[External Libraries]
Configuration Example
## Create lib directory
mkdir -p libs
## Generate manifest with classpath
cat > META-INF/MANIFEST.MF << EOF
Manifest-Version: 1.0
Main-Class: com.labex.MainApplication
Class-Path: libs/commons-lang3-3.12.0.jar
EOF
Scenario 3: Multi-Module Project Configuration
Manifest Attributes Table
Attribute |
Purpose |
Example |
Implementation-Title |
Project Name |
LabEx Application |
Implementation-Version |
Project Version |
1.0.0 |
Built-By |
Build Environment |
LabEx Developer |
Advanced Manifest Configuration
cat > META-INF/MANIFEST.MF << EOF
Manifest-Version: 1.0
Main-Class: com.labex.MainApplication
Implementation-Title: LabEx Multi-Module Project
Implementation-Version: 1.0.0
Built-By: LabEx Development Team
Created-By: Java 11
EOF
Scenario 4: Security and Signing
Manifest Security Configuration
## Generate keystore
keytool -genkey -keystore labex.keystore -alias labexkey
## Sign JAR with manifest
jarsigner -keystore labex.keystore app.jar labexkey
Verification Command
## Verify JAR signature
jarsigner -verify app.jar
Common Manifest Troubleshooting
graph TD
A[Manifest Issues] --> B[Incorrect Main-Class]
A --> C[Missing Dependencies]
A --> D[Encoding Problems]
A --> E[Path Misconfigurations]
Best Practices Checklist
- Always specify
Main-Class
- Use relative paths for dependencies
- Keep manifest files clean
- Test JAR execution thoroughly
- Use build tools for consistent configuration
Example: Complete Workflow
## Full manifest creation workflow
mkdir -p /home/labex/manifest-project
cd /home/labex/manifest-project
## Compile source
javac src/main/java/com/labex/MainApplication.java
## Create manifest
echo "Main-Class: com.labex.MainApplication" > META-INF/MANIFEST.MF
## Package JAR
jar cvfm app.jar META-INF/MANIFEST.MF -C src/main/java .
## Run application
java -jar app.jar
By exploring these practical examples, developers can gain comprehensive insights into manifest configuration and management in Java applications.