This discussion is archived
8 Replies Latest reply: Feb 10, 2012 9:24 AM by 916606 RSS

URGENT: PDF generation Error when executing .jat

916606 Newbie
Currently Being Moderated
Hi Guys.

Here is the thing. I have a sample code on a java class (see it below), with this I can perfectly create the PDF file when I run the project from netbeans 6.9 ... however, when I create the .jar file for the project and try to execute it, then I get an Error message saying that an exception has happened (this is not handled, despite the existing try-catch)... Could you please try it yourselve and/or help me out with this...

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Date;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
import javax.swing.JOptionPane;

public class GeneratingPDF_V2 {

public static void main(String[] args) {
try {
OutputStream file = new FileOutputStream(new File("C:\\GD\\Test.pdf"));

Document document = new Document();
PdfWriter.getInstance(document, file);
document.open();
document.add(new Paragraph("Blabla"));
document.add(new Paragraph(new Date().toString()));

document.close();
file.close();

} catch (Exception e) {

JOptionPane.showMessageDialog(null,e.getMessage()) ;
}
}

}//END OF GeneratingPDF_V2 --------------------------------------------------------------
  • 1. Re: URGENT: PDF generation Error when executing .jat
    DarrylBurke Guru Moderator
    Currently Being Moderated
    Cross posted
    http://www.java-forums.org/advanced-java/55358-problem-printing-pdf-only-caused-when-using-jar-file-not-netbeans-gui.html

    Also in the wrong forum here, moving from 'Sun Java Studio Creator' to 'New to Java'

    db
  • 2. Re: URGENT: PDF generation Error when executing .jat
    EJP Guru
    Currently Being Moderated
    I get an Error message saying that an exception has happened
    What exception? Post the complete stack trace. You will never get anywhere just saying 'an exception has happened'.
  • 3. Re: URGENT: PDF generation Error when executing .jat
    916606 Newbie
    Currently Being Moderated
    Hi EJP.

    The exact message I am getting says "An Exception has happened" and nothing else. I believe that if an exception happens, it should get caught within the try catch statemente in the code and then prompted to me on screen, but that is not what is happening. Please indicate me if there is another exception type I am missing to catch or other way to trace on this, as it only happens when I run the .jar file, running it through netbeans gui works ok... where could be the difference!?
  • 4. Re: URGENT: PDF generation Error when executing .jat
    gimbal2 Guru
    Currently Being Moderated
    913603 wrote:
    The exact message I am getting says "An Exception has happened" and nothing else. I believe that if an exception happens, it should get caught within the try catch statemente in the code and then prompted to me on screen, but that is not what is happening. Please indicate me if there is another exception type I am missing to catch or other way to trace on this, as it only happens when I run the .jar file, running it through netbeans gui works ok... where could be the difference!?
    Likely a mismatch in library dependencies. Netbeans itself is also just Java, but it manages the classpath for you. When you run outside of Netbeans you're on your own.
  • 5. Re: URGENT: PDF generation Error when executing .jat
    aksarben Journeyer
    Currently Being Moderated
    Forum etiquette tip: Putting URGENT in the subject line won't get you an answer any faster. It just annoys people & may even slow down response time, or prevent you from getting answer at all. Remember, your emergency is not our emergency.
  • 6. Re: URGENT: PDF generation Error when executing .jat
    gimbal2 Guru
    Currently Being Moderated
    aksarben wrote:
    Forum etiquette tip: Putting URGENT in the subject line won't get you an answer any faster. It just annoys people & may even slow down response time, or prevent you from getting answer at all. Remember, your emergency is not our emergency.
    Give it up dude, just because you convert one person does not mean that you convert all the future newcomers as well - its a futile effort you're making. If you must, direct people to the forum guidelines.
  • 7. Re: URGENT: PDF generation Error when executing .jat
    796440 Guru
    Currently Being Moderated
    aksarben wrote:
    Forum etiquette tip: Putting URGENT in the subject line won't get you an answer any faster. It just annoys people & may even slow down response time, or prevent you from getting answer at all. Remember, your emergency is not our emergency.
    PLUSPLUS
    gimbal2 wrote:
    its a futile effort you're making.
    PLUSPLUS
  • 8. Re: URGENT: PDF generation Error when executing .jat
    916606 Newbie
    Currently Being Moderated
    Hi Gimbal2.

    Thanks for your tip, it help me solving the problem is was having.

    I simply deleted the libraries and did the entire import process again, as well as adding these libraries to my project and it solve the issue. Now the .jar file works fine!!!

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points