使用Google的示例代码并获取java.lang.NoClassDefFoundError:javax / xml / bind / JAXBException

时间:2019-08-30 14:23:12

标签: java xml google-adwords

我想运行此代码来测试Google Ads API-该代码应下载CSV文件,但是显示错误,我似乎找不到不包含使用Maven的解决方案。

我用于所有示例代码的页面是https://developers.google.com/adwords/api/docs/guides/samples-use-cases

我正在尝试获取Google Ads帐户中某些关键字的最近7天数据,以便我们可以在Java程序中自动分析数据。

public static void main(String[] args) throws Exception
{
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential = new OfflineCredentials.Builder()
            .forApi(Api.ADWORDS)
            .fromFile()
            .build()
            .generateCredential();

    // Construct an AdWordsSession.
    AdWordsSession session = new AdWordsSession.Builder()
            .fromFile()
            .withOAuth2Credential(oAuth2Credential)
            .build();

    // Create report definition.
    ReportDefinition reportDefinition = new ReportDefinition();
    reportDefinition.setReportName("Criteria performance report #" + System.currentTimeMillis());
    reportDefinition.setDateRangeType(ReportDefinitionDateRangeType.LAST_7_DAYS);
    reportDefinition.setReportType(ReportDefinitionReportType.KEYWORDS_PERFORMANCE_REPORT);
    reportDefinition.setDownloadFormat(DownloadFormat.CSV);

    Selector selector = new Selector();
    selector.getFields().addAll(Lists.newArrayList("CampaignId",
            "AdGroupId",
            "Id",
            "CriteriaType",
            "Criteria",
            "FinalUrls",
            "Impressions",
            "Clicks",
            "Cost"));

    ReportDownloadResponse response =
            new ReportDownloader(session).downloadReport(reportDefinition);
    response.saveToFile("reportFile");

}

错误消息是:   https://i.stack.imgur.com/AEYo3.png

线程“主”中的异常java.lang.NoClassDefFoundError:javax / xml / bind / JAXBException     com.google.api.ads.adwords.lib.utils.v201809.XmlReportDefinitionRequest。(XmlReportDefinitionRequest.java:32)     com.google.api.ads.adwords.lib.utils.v201809.ReportDownloader.downloadReport(ReportDownloader.java:65)     在main.main(main.java:74) 引起原因:java.lang.ClassNotFoundException:javax.xml.bind.JAXBException     在java.base / jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)     在java.base / jdk.internal.loader.ClassLoaders $ AppClassLoader.loadClass(ClassLoaders.java:178)     在java.base / java.lang.ClassLoader.loadClass(ClassLoader.java:521)     ...还有3个

0 个答案:

没有答案