更改每个人的权限时,ClassNotFoundException HttpServletRequest,java.io.File

时间:2014-08-16 01:23:29

标签: java file

我试图设置文件的权限,因为我之后收到警告和NoClassDefFoundError,我尝试使用

file.setWritable(true,false);
file.setExecutable(true,false);
file.setReadable(true,false);

但是不起作用,文件是这样创建的:

private static final java.io.File DATA_STORE_DIR
        = new java.io.File(System.getProperty("user.home"), ".store/calendar_sample");

这适用于Google Calendar V3 API,我正在使用Mac,这里项目执行没有问题,但是当我在Windows 7中运行时,问题就开始出现并且.jar崩溃了

当文件没有权限时,似乎会触发异常。

这是整个班级

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");
 }
}

这是我尝试运行jar时得到的结果 enter image description here

1 个答案:

答案 0 :(得分:0)

这与Java无法在Windows 7上解析系统属性"user.home"的问题有关。在Unix和类Unix操作系统上,此属性值将被评估为环境变量{{1}比如$HOME。但是,在Windows 7上,Java不会将其解释为默认用户目录/home/my_username。可以从相关的post找到更多详细信息。