You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@netbeans.apache.org by Chad Cordero <cc...@csusb.edu> on 2018/04/17 21:08:37 UTC

Generated distributions give FileNotFoundException

I have a project I’ve been working on that runs fine from the NetBeans console, but when I untar the distribution and run it from command line it gives me a FileNotFoundException.  I’m using NetBeans IDE 8.2 (Build 201609300101) and the gradle plugin.



Build.gradle:

apply plugin: 'java'

apply plugin: 'application'



mainClassName = 'GmailSettings/Main'

sourceCompatibility = 1.7

targetCompatibility = 1.7

version = '1.0'



repositories {

    mavenCentral()

}



dependencies {

    compile 'com.google.api-client:google-api-client:1.23.0'

    compile 'com.google.oauth-client:google-oauth-client-jetty:1.23.0'

    compile 'com.google.apis:google-api-services-gmail:v1-rev83-1.23.0'

    compile group: 'commons-cli', name: 'commons-cli', version: '1.4'



    testCompile group: 'junit', name: 'junit', version: '4.12'

}



GmailSettings/GmailSettingsService.java:

…

Public class GmailSettingsService {

…

/**

     * Path to the Service Account's Private Key file

     */

    private static final String SERVICE_ACCOUNT_PKCS12_FILE_PATH = GmailSettingsService.class.getResource("GmailSettings.p12").getPath();



…

/**

     * Build and return an authorized Gmail client service.

     *

     * @return an authorized Gmail client service

     * @throws IOException

     */

    private static Gmail getGmailService(String userName) throws IOException, GeneralSecurityException {

                …

                GoogleCredential credential = new GoogleCredential.Builder()

                .setTransport(httpTransport)

                .setJsonFactory(jsonFactory)

                .setServiceAccountId(SERVICE_ACCOUNT_EMAIL)

                .setServiceAccountScopes(SCOPES)

                .setServiceAccountUser(userName)

                .setServiceAccountPrivateKeyFromP12File(

                        new java.io.File(SERVICE_ACCOUNT_PKCS12_FILE_PATH))

                .build();



                …

}



Output:

$ bin/GmailSettings-1.0/bin/GmailSettings --help

Exception in thread "main" java.io.FileNotFoundException: file:/Users/000017913/bin/GmailSettings-1.0/lib/GmailSettings-1.0.jar!/GmailSettings/GmailSettings.p12 (No such file or directory)

       at java.io.FileInputStream.open0(Native Method)

       at java.io.FileInputStream.open(FileInputStream.java:195)

       at java.io.FileInputStream.<init>(FileInputStream.java:138)

       at com.google.api.client.googleapis.auth.oauth2.GoogleCredential$Builder.setServiceAccountPrivateKeyFromP12File(GoogleCredential.java:714)

       at GmailSettings.GmailSettingsService.getGmailService(GmailSettingsService.java:65)

       at GmailSettings.GmailSettingsService.<init>(GmailSettingsService.java:84)

       at GmailSettings.Main.main(Main.java:35)

ITS-PLECS-60504:~ 000017913$ jar tf bin/GmailSettings-1.0/lib/GmailSettings-1.0.jar

META-INF/

META-INF/MANIFEST.MF

GmailSettings/

GmailSettings/Constants.class

GmailSettings/GmailSettingsService.class

GmailSettings/GmailSettings.class

GmailSettings/DateString.class

GmailSettings/Main.class

GmailSettings/Cli.class

GmailSettings/GmailSettings.p12





--
Chad Cordero
Information Technology Consultant
Enterprise & Cloud Services
Information Technology Services
California State University, San Bernardino
5500 University Pkwy
San Bernardino, CA 92407-2393
Main Line: 909/537-7677
Direct Line: 909/537-7281
Fax: 909/537-7141
http://support.csusb.edu/

---
Disclaimer: This e-mail message is for the sole use of the intended recipient(s) and may contain confidential and privileged information protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer.

Re: Generated distributions give FileNotFoundException

Posted by Chad Cordero <cc...@csusb.edu>.
Sorry for posting this here.  It turned out to be a coding issue and not a NetBeans configuration issue.

--
Chad Cordero
Information Technology Consultant
Enterprise & Cloud Services
Information Technology Services
California State University, San Bernardino
5500 University Pkwy
San Bernardino, CA 92407-2393
Main Line: 909/537-7677
Direct Line: 909/537-7281
Fax: 909/537-7141
http://support.csusb.edu/

---
Disclaimer: This e-mail message is for the sole use of the intended recipient(s) and may contain confidential and privileged information protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer.
From: Chad Cordero <cc...@csusb.edu>
Date: Tuesday, April 17, 2018 at 2:08 PM
To: "users@netbeans.incubator.apache.org" <us...@netbeans.incubator.apache.org>
Subject: Generated distributions give FileNotFoundException


I have a project I’ve been working on that runs fine from the NetBeans console, but when I untar the distribution and run it from command line it gives me a FileNotFoundException.  I’m using NetBeans IDE 8.2 (Build 201609300101) and the gradle plugin.



Build.gradle:

apply plugin: 'java'

apply plugin: 'application'



mainClassName = 'GmailSettings/Main'

sourceCompatibility = 1.7

targetCompatibility = 1.7

version = '1.0'



repositories {

    mavenCentral()

}



dependencies {

    compile 'com.google.api-client:google-api-client:1.23.0'

    compile 'com.google.oauth-client:google-oauth-client-jetty:1.23.0'

    compile 'com.google.apis:google-api-services-gmail:v1-rev83-1.23.0'

    compile group: 'commons-cli', name: 'commons-cli', version: '1.4'



    testCompile group: 'junit', name: 'junit', version: '4.12'

}



GmailSettings/GmailSettingsService.java:

…

Public class GmailSettingsService {

…

/**

     * Path to the Service Account's Private Key file

     */

    private static final String SERVICE_ACCOUNT_PKCS12_FILE_PATH = GmailSettingsService.class.getResource("GmailSettings.p12").getPath();



…

/**

     * Build and return an authorized Gmail client service.

     *

     * @return an authorized Gmail client service

     * @throws IOException

     */

    private static Gmail getGmailService(String userName) throws IOException, GeneralSecurityException {

                …

                GoogleCredential credential = new GoogleCredential.Builder()

                .setTransport(httpTransport)

                .setJsonFactory(jsonFactory)

                .setServiceAccountId(SERVICE_ACCOUNT_EMAIL)

                .setServiceAccountScopes(SCOPES)

                .setServiceAccountUser(userName)

                .setServiceAccountPrivateKeyFromP12File(

                        new java.io.File(SERVICE_ACCOUNT_PKCS12_FILE_PATH))

                .build();



                …

}



Output:

$ bin/GmailSettings-1.0/bin/GmailSettings --help

Exception in thread "main" java.io.FileNotFoundException: file:/Users/000017913/bin/GmailSettings-1.0/lib/GmailSettings-1.0.jar!/GmailSettings/GmailSettings.p12 (No such file or directory)

       at java.io.FileInputStream.open0(Native Method)

       at java.io.FileInputStream.open(FileInputStream.java:195)

       at java.io.FileInputStream.<init>(FileInputStream.java:138)

       at com.google.api.client.googleapis.auth.oauth2.GoogleCredential$Builder.setServiceAccountPrivateKeyFromP12File(GoogleCredential.java:714)

       at GmailSettings.GmailSettingsService.getGmailService(GmailSettingsService.java:65)

       at GmailSettings.GmailSettingsService.<init>(GmailSettingsService.java:84)

       at GmailSettings.Main.main(Main.java:35)

ITS-PLECS-60504:~ 000017913$ jar tf bin/GmailSettings-1.0/lib/GmailSettings-1.0.jar

META-INF/

META-INF/MANIFEST.MF

GmailSettings/

GmailSettings/Constants.class

GmailSettings/GmailSettingsService.class

GmailSettings/GmailSettings.class

GmailSettings/DateString.class

GmailSettings/Main.class

GmailSettings/Cli.class

GmailSettings/GmailSettings.p12





--
Chad Cordero
Information Technology Consultant
Enterprise & Cloud Services
Information Technology Services
California State University, San Bernardino
5500 University Pkwy
San Bernardino, CA 92407-2393
Main Line: 909/537-7677
Direct Line: 909/537-7281
Fax: 909/537-7141
http://support.csusb.edu/

---
Disclaimer: This e-mail message is for the sole use of the intended recipient(s) and may contain confidential and privileged information protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer.