Open PDF in java on another machine

6

I made a function that I can open a PDF, but this function is only working on my local machine. When I run the .jar generated on another machine, an error is issued that the PDF file does not exist.

The part that performs this function:

 try { 

   java.awt.Desktop desktop = java.awt.Desktop.getDesktop();           
   desktop.open(new File("/manual.pdf")); 

} catch (IOException ex) {
    Logger.getLogger(JFrameInicio.class.getName()).log(Level.SEVERE, null, ex);
    System.out.println(ex);
} 

The PDF file is in the following location: \ Documents \ NetBeansProjects \ Rectory \ src \ rectory

To create the JAR, I use the package for store method that in my thinking creates a jar with all the necessary files.

I think the PDF is being included in the final jar because without putting the PDF in the src folder, the jar has a final size of 3 MB, my pdf also has 3 MB. When I create the jar with the PDF file in the src folder, the final .jar is 6MB in size (I believe it is the jar + PDF file)

    
asked by anonymous 25.11.2015 / 11:14

2 answers

1

Use a path that will always validate on any machine such as "C: /" or use relative paths such as the System.getProperty("user.home") user folder or the path of the /

Make sure the PDF is in the path indicated.

    
31.05.2016 / 15:11
0

When creating the File object, use ./record / manual.pdf as NetBeans

So, your piece of code would look like:

try { 

   java.awt.Desktop desktop = java.awt.Desktop.getDesktop();           
   desktop.open(new File("./reitoria/manual.pdf")); 

} catch (IOException ex) {
    Logger.getLogger(JFrameInicio.class.getName()).log(Level.SEVERE, null, ex);
    System.out.println(ex);
} 
    
18.02.2017 / 17:50