In attempting to create my first executable file using Maven I encountered problems and am now attempting to use install4j instead. In order to retain my dependencies, I have downloaded the jars listed in my pom.xml, added them to the build path, and removed pom.xml. Now, some of my jars seem not to have imported correctly. I have tried both the latest versions, and the older versions that were working fine in my maven project, neither work.
The ultimate problem I'm trying to solve is that when I built with install4j my exe wouldn't run, which I assumed to be due to the dependencies in my pom.xml not being included (as I wasn't building using maven)
These are my jars:
- google-api-client-1.3.2.jar
- google-api-services-sheets-v4-rev614-1.18.0-rc.jar
- google-oauth-client-jetty-1.31.4.jar
- commons-io-1.3.2.jar (don't think this is used)
These are the imports that are working:
- import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
- import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
- import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
- import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
- import com.google.api.services.sheets.v4.Sheets;
These are the imports that are not working:
- import com.google.api.client.auth.oauth2.Credential;
- import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
- import com.google.api.client.http.javanet.NetHttpTransport;
- import com.google.api.client.json.JsonFactory;
- import com.google.api.client.json.jackson2.JacksonFactory;
- import com.google.api.client.util.store.FileDataStoreFactory;
This is a MRE of my code:
package misc;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.util.store.FileDataStoreFactory;
import com.google.api.services.sheets.v4.Sheets;
public class GoogleSheetsStuff {
private static final String APPLICATION_NAME = "Google Sheets API Java Quickstart";
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
private static final String TOKENS_DIRECTORY_PATH = "tokens2";
private static final List<String> SCOPES = Collections.singletonList(SheetsScopes.SPREADSHEETS);
private static final String CREDENTIALS_FILE_PATH = "/credentials.json";
private static Credential getCredentials(final NetHttpTransport HTTP_TRANSPORT) throws IOException {
InputStream in = GoogleSheetsStuff.class.getResourceAsStream(CREDENTIALS_FILE_PATH);
if (in == null) {
throw new FileNotFoundException("Resource not found: " + CREDENTIALS_FILE_PATH);
}
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
.setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH)))
.setAccessType("offline")
.build();
LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build();
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}
public static Sheets buildService () throws GeneralSecurityException, IOException {
final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
Sheets service = new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT))
.setApplicationName(APPLICATION_NAME)
.build();
return service;
}
}