2

I try to create a jar and add a manifest since my default class cannot be found no matter what I do I checked may threads on SO, still no luck

here is how I create my class and create the jar file

javac.exe -d dist -classpath ./pdfbox-app-2.0.12.jar Pdf.java
jar.exe -cvfm Pdf.jar manifest.txt dist/com/company/*.class
jar.exe tf Pdf.jar 
java.exe -jar Pdf.jar

the jar command gives :

added manifest
adding: dist/com/company/Pdf.class(in = 1150) (out= 658)(deflated 42%)

here is what is set in the manifest.txt

Manifest-Version: 1.0
Created-By: My Name
Main-Class: com.company.Pdf

as I checked the manifest in the file, it is not update with my lines

here is the java code if needed :

package com.company;

import java.io.File;
import java.io.IOException;

import org.apache.pdfbox.pdmodel.PDDocument; 
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException;

public class Pdf {
    public static void main(String[] args) {
        if(args.length<2)
        {
            System.out.println("Error ! need 2 parameters");
        }
        try
        {
            //Load the document
            PDDocument pDDocument = PDDocument.load(new File(args[0]));    
            PDAcroForm pDAcroForm = pDDocument.getDocumentCatalog().getAcroForm();

            //Fill the document


            //Flatten the document
            pDAcroForm.flatten();

            //Save the document
            pDDocument.save(args[1]);
            pDDocument.close();
        }
        catch(InvalidPasswordException e)
        {

        }
        catch(IOException e)
        {

        }
    }
}

what do I do wrong ?

thanks

[ANSWER]

here is how I do it

del Pdf.jar
javac -d build -classpath lib/pdfbox-app-2.0.12.jar Pdf.java
jar -cfM Pdf.jar -C build com 
jar umf META-INF/MANIFEST.MF Pdf.jar
jar tf Pdf.jar 

here is the test

java -jar Pdf.jar 

the manifest I use

Manifest-Version: 1.0
Created-By: ......
Main-Class: com.company.Pdf
Class-Path: lib/pdfbox-app-2.0.12.jar
phil123456
  • 211
  • 3
  • 13
  • you can check this link https://stackoverflow.com/questions/9689793/cant-execute-jar-file-no-main-manifest-attribute – Bhumi Nandan Chettri Nov 26 '18 at 11:57
  • did not help, already tried these, is the META-INF/MANIFEST.MF mandatory on the command line ? – phil123456 Nov 26 '18 at 12:04
  • just tried, does not work, my issue is that the manifest is NOT UPDATED while jar says it is – phil123456 Nov 26 '18 at 12:06
  • ok, I first used "cvfM" so it does not create a manifest, hten I did an "umf" to update the manifest..it updates everything except the Main-Class entry point which is missiing – phil123456 Nov 26 '18 at 12:13
  • apparently I have to add extra lines to the manifest otherwise the last lines of my manifest are not copied...probably a bug – phil123456 Nov 26 '18 at 12:17
  • Your jar is incorrect. No manifest will be able to fix that. The dist directory must not be in the jar file. – JB Nizet Nov 26 '18 at 12:20
  • I read on SO I had to respect the directory structure – phil123456 Nov 26 '18 at 12:22
  • Yes, precisely. And the root package is com, not dist. dist is just a directory where you chose to put your class files. Forget about the manifest, and just use `jar cf pdf.jar -C dist com`. And use `java -cp pdf.jar:pdfbox-app-2.0.12.jar com.company.Pdf`. BTW, you're not respecting the directory structure since your Pdf.java file is not under a com/company folder. – JB Nizet Nov 26 '18 at 12:23
  • wow, it worked...it found may class..thanks – phil123456 Nov 26 '18 at 12:35

0 Answers0