I'm trying to set permissions to a file because I'm getting warnings and a NoClassDefFoundError after that, I tried using
file.setWritable(true,false);
file.setExecutable(true,false);
file.setReadable(true,false);
But doesn't work, the file is created this way:
private static final java.io.File DATA_STORE_DIR
= new java.io.File(System.getProperty("user.home"), ".store/calendar_sample");
This is for Google Calendar V3 API, i'm using a Mac, and here the project executes with no problem, but when I run it in a Windows 7 the problem start to show and the .jar crashes
The Exception seems to trigger when the file don't have the permissions.
this is the whole class
public class GoogleCalendar2 {
private static final String APPLICATION_NAME = "expeDiente";
private static final java.io.File DATA_STORE_DIR
= new java.io.File("C:\\\\\\\\", ".store/calendar_sample");
private static FileDataStoreFactory dataStoreFactory;
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
private static HttpTransport httpTransport;
@SuppressWarnings("unused")
private static Calendar client;
String id = "";
public GoogleCalendar2() throws GeneralSecurityException, IOException, Exception {
DATA_STORE_DIR.setWritable(true, false);
DATA_STORE_DIR.setExecutable(true, false);
DATA_STORE_DIR.setReadable(true, false);
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
Credential credential = authorize();
client = new Calendar.Builder(httpTransport, JSON_FACTORY, credential)
.setApplicationName(APPLICATION_NAME).build();
}
/**
* Authorizes the installed application to access user's protected data.
*/
private static Credential authorize() throws Exception {
Set<String> scopes = new HashSet<String>();
scopes.add(CalendarScopes.CALENDAR);
scopes.add(CalendarScopes.CALENDAR_READONLY);
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
httpTransport, JSON_FACTORY, "user id google", "user secrets", scopes)
.setDataStoreFactory(dataStoreFactory)
.build();
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}
}
this is what I get when I try to run the jar