【问题标题】:How to resolve cannot find symbol error?如何解决找不到符号错误?
【发布时间】:2013-01-15 06:38:10
【问题描述】:

我正在尝试使用IBM 提供的Java 程序。请参阅下面的代码。当我尝试编译这个程序时,

C:\Temp>"C:\Program Files (x86)\Java\jdk1.6.0_25\bin\javac.exe" GetOrphanMyFolde
rs.java

我收到一个错误提示

GetOrphanMyFolders.java:96: cannot find symbol
symbol  : variable PropEnum
location: class GetOrphanMyFolders
                                 PropEnum.canBurst      ,
                                 ^
GetOrphanMyFolders.java:97: cannot find symbol
symbol  : variable PropEnum
location: class GetOrphanMyFolders
                                 PropEnum.capabilities   ,
                                 ^

我是Java菜鸟,这个错误的原因是什么?我正在使用的程序在这里

/**
 * Licensed Material - Property of IBM
 * © Copyright IBM Corp. 2012
 *
 * GetOrphanMyFolders.java
 *
 * Description: Technote 1340789 - SDK Sample: How to recover the My Folders of users that no longer exist in the Authentication Provider
 *
 * Tested with: IBM Cognos BI 10.1.1, IBM Java 5.0, Axis 1.4
 *
 */

import java.util.Vector;

import javax.xml.namespace.QName;

import org.apache.axis.client.Stub;
import org.apache.axis.message.SOAPHeaderElement;

import com.cognos.developer.schemas.bibus._3.BaseClass;
import com.cognos.developer.schemas.bibus._3.BiBusHeader;
import com.cognos.developer.schemas.bibus._3.ContentManagerService_PortType;
import com.cognos.developer.schemas.bibus._3.ContentManagerService_ServiceLocator;
import com.cognos.developer.schemas.bibus._3.CopyOptions;
import com.cognos.developer.schemas.bibus._3.PropEnum;
import com.cognos.developer.schemas.bibus._3.QueryOptions;
import com.cognos.developer.schemas.bibus._3.SearchPathMultipleObject;
import com.cognos.developer.schemas.bibus._3.SearchPathSingleObject;
import com.cognos.developer.schemas.bibus._3.Sort;
import com.cognos.developer.schemas.bibus._3.UpdateActionEnum;
import com.cognos.developer.schemas.bibus._3.XmlEncodedXML;

public class GetOrphanMyFolders
{
    //TODO: change the following variables depending on your installation and setup

    //--- begin changes ----
    private static String dispatcherURL = "http://localhost:9300/p2pd/servlet/dispatch";

    //Change the next three variables to a valid namespace ID as defined in Cognos Configuration and NOT the namespace name
    //Provide a valid user ID and password if Anonymous is disabled
    private static String nameSpaceID   = "Cognos";
    private static String userName      = "admin";
    private static String password      = "password";

    // define where you are copying the orphaned my folders to
    private static String targetLocation = "/content/folder[@name='OrphanedMyFolders']";
    //--- end changes ---

    //Services to be used in the sample
    private ContentManagerService_PortType cmService = null;

    private String[] getAllMyFoldersSearchPaths(String namespaceID)
    {
        String listOfAccountSP [] = null;
        PropEnum props[] = new PropEnum[] {PropEnum.searchPath, PropEnum.defaultName, PropEnum.portalPage};
        Sort sOpt[] = new Sort[]{}; 
        QueryOptions qOpt = new QueryOptions(); 
        try
        {
            // get the template user's Account object. 
            BaseClass template[] = cmService.query(new SearchPathMultipleObject("//folder"), props, sOpt, qOpt);
            listOfAccountSP = new String [template.length];

            for (int x=0;x<template.length;x++)
            {
                if ( template[x].getSearchPath().getValue().indexOf(")/folder[@name='My Folders']")>0 )
                {
                    listOfAccountSP[x]=template[x].getSearchPath().getValue();
                }
            }
        }
        catch (Exception e)
        {
            System.out.println(e);
            e.printStackTrace();
        }
        return listOfAccountSP;
    }

    private PropEnum[] getAllPropEnum ()
      {
        PropEnum properties[] = new PropEnum[]{
                 PropEnum.active, 
                 PropEnum.actualCompletionTime,
                 PropEnum.actualExecutionTime ,
                 PropEnum.advancedSettings ,
                 PropEnum.ancestors ,
                 PropEnum.asOfTime ,
                 PropEnum.base ,
                 PropEnum.brsAffineConnections, 
                 PropEnum.brsMaximumProcesses ,
                 PropEnum.brsNonAffineConnections, 
                 PropEnum.burstKey ,
                 PropEnum.businessPhone,             
                 PropEnum.canBurst      ,       
                 PropEnum.capabilities   ,          
                 PropEnum.capacity        ,     
                 PropEnum.closeConnectionCommands,             
                 PropEnum.closeSessionCommands    ,         
                 PropEnum.configuration            , 
                 PropEnum.connections             ,
                 PropEnum.connectionString         ,    
                 PropEnum.consumers             ,
                 PropEnum.contact             ,
                 PropEnum.contactEMail         ,    
                 PropEnum.contentLocale         ,    
                 PropEnum.creationTime           ,  
                 PropEnum.credential             ,
                 PropEnum.credentialNamespaces    ,         
                 PropEnum.credentials             ,
                 PropEnum.cubeContentName          ,   
                 PropEnum.dailyPeriod             ,
                 PropEnum.data             ,
                 PropEnum.dataBlocks        ,     
                 PropEnum.dataSize           ,  
                 PropEnum.dataType            , 
                 PropEnum.defaultDescription   ,          
                 PropEnum.defaultName           ,  
                 PropEnum.defaultOutputFormat    ,         
                 PropEnum.defaultScreenTip        ,     
                 PropEnum.defaultTriggerDescription,
                 PropEnum.deployedObject ,
                 PropEnum.deployedObjectAncestorDefaultNames, 
                 PropEnum.deployedObjectClass ,
                 PropEnum.deployedObjectDefaultName, 
                 PropEnum.deployedObjectStatus      ,       
                 PropEnum.deployedObjectUsage        ,     
                 PropEnum.deploymentOptions           ,  
                 PropEnum.description             ,
                 PropEnum.disabled             ,
                 PropEnum.dispatcherID          ,   
                 PropEnum.dispatcherPath         ,    
                 PropEnum.displaySequence         ,    
                 PropEnum.email             ,
                 PropEnum.endDate            , 
                 PropEnum.endType             ,
                 PropEnum.eventID             ,
                 PropEnum.everyNPeriods        ,     
                 PropEnum.executionFormat        ,     
                 PropEnum.executionLocale         ,    
                 PropEnum.executionPageDefinition  ,           
                 PropEnum.executionPageOrientation  ,           
                 PropEnum.executionPrompt            , 
                 PropEnum.faxPhone             ,
                 PropEnum.format             ,
                 PropEnum.gateway             ,
                 PropEnum.givenName            , 
                 PropEnum.governors             ,
                 PropEnum.hasChildren            , 
                 PropEnum.hasMessage             ,
                 PropEnum.hasPrompts             ,
                 PropEnum.height             ,
                 PropEnum.homePhone           ,  
                 PropEnum.horizontalElementsRenderingLimit,
                 PropEnum.identity ,
                 PropEnum.isolationLevel, 
                 PropEnum.lastConfigurationModificationTime, 
                 PropEnum.lastPage ,
                 PropEnum.loadBalancingMode, 
                 PropEnum.locale ,
                 PropEnum.location, 
                 PropEnum.members ,
                 PropEnum.message ,
                 PropEnum.metadataModel ,
                 PropEnum.mobilePhone ,
                 PropEnum.model ,
                 PropEnum.modelName ,
                 PropEnum.modificationTime ,
                 PropEnum.monthlyAbsoluteDay ,
                 PropEnum.monthlyRelativeDay ,
                 PropEnum.monthlyRelativeWeek ,
                 PropEnum.name ,
                 PropEnum.namespaceFormat ,
                 PropEnum.objectClass ,
                 PropEnum.openConnectionCommands ,
                 PropEnum.openSessionCommands ,
                 PropEnum.options ,
                 PropEnum.output ,
                 PropEnum.owner ,
                 PropEnum.ownerPassport ,
                 PropEnum.packageBase ,
                 PropEnum.page ,
                 PropEnum.pageOrientation ,
                 PropEnum.pagerPhone ,
                 PropEnum.parameters ,
                 PropEnum.parent ,
                 PropEnum.paths ,
                 PropEnum.permissions ,
                 PropEnum.policies ,
                 PropEnum.portalPage ,
                 PropEnum.position ,
                 PropEnum.postalAddress ,
                 PropEnum.printerAddress ,
                 PropEnum.productLocale ,
                 PropEnum.qualifier ,
                 PropEnum.recipients ,
                 PropEnum.recipientsEMail ,
                 PropEnum.related ,
                 PropEnum.replacement ,
                 PropEnum.requestedExecutionTime ,
                 PropEnum.retentions ,
                 PropEnum.rsAffineConnections ,
                 PropEnum.rsMaximumProcesses ,
                 PropEnum.rsNonAffineConnections ,
                 PropEnum.rsQueueLimit ,
                 PropEnum.runAsOwner ,
                 PropEnum.runningState ,
                 PropEnum.runOptions ,
                 PropEnum.screenTip ,
                 PropEnum.searchPath ,
                 PropEnum.searchPathForURL ,
                 PropEnum.sequencing ,
                 PropEnum.serverGroup ,
                 PropEnum.source ,
                 PropEnum.specification ,
                 PropEnum.startAsActive ,
                 PropEnum.startDate ,
                 PropEnum.state ,
                 PropEnum.status ,
                 PropEnum.stepObject ,
                 PropEnum.surname ,
                 PropEnum.target ,
                 PropEnum.taskID ,
                 PropEnum.timeZoneID ,
                 PropEnum.triggerDescription ,
                 PropEnum.triggerName ,
                 PropEnum.type ,
                 PropEnum.unit ,
                 PropEnum.uri ,
                 PropEnum.usage ,
                 PropEnum.user ,
                 PropEnum.userCapabilities ,
                 PropEnum.userCapability ,
                 PropEnum.userName ,
                 PropEnum.version ,
                 PropEnum.verticalElementsRenderingLimit ,
                 PropEnum.viewed ,
                 PropEnum.weeklyFriday ,
                 PropEnum.weeklyMonday ,
                 PropEnum.weeklySaturday ,
                 PropEnum.weeklySunday ,
                 PropEnum.weeklyThursday ,
                 PropEnum.weeklyTuesday ,
                 PropEnum.weeklyWednesday ,
                 PropEnum.width ,
                 PropEnum.yearlyAbsoluteDay, 
                 PropEnum.yearlyAbsoluteMonth, 
                 PropEnum.yearlyRelativeDay ,
                 PropEnum.yearlyRelativeMonth, 
                 PropEnum.yearlyRelativeWeek ,

        };
        return properties;
      }

    private String[][] getAllCIs(String namespaceID)
    {
        String listOfCIs [][] = null;

        String searchPath = "CAMID('"+namespaceID+"')//account";
        PropEnum props[] = new PropEnum[] {PropEnum.searchPath, PropEnum.defaultName, PropEnum.portalPage};
        Sort sOpt[] = new Sort[]{}; 
        QueryOptions qOpt = new QueryOptions(); 
        try
        {
            // get the template user's Account object. 
            BaseClass template[] = cmService.query(new SearchPathMultipleObject(searchPath), props, sOpt, qOpt);
            listOfCIs = new String [2] [template.length];

            for (int x=0;x<template.length;x++)
            {
                    listOfCIs[0][x]=template[x].getSearchPath().getValue();
                    listOfCIs[1][x]=template[x].getDefaultName().getValue();
            }
        }
        catch (Exception e)
        {
            System.out.println(e);
            e.printStackTrace();
        }

        return listOfCIs;

    }

    private void moveMF2PF(String path, String targetLocation)
    {
        String userSearchPaths = path ;
        PropEnum props[] = getAllPropEnum();
        String user = path.substring(0, path.indexOf("/folder[@name='My Folders']"));

        try
        {
            //Query the Content Store for all objects in My Folders for user userName
            BaseClass bc[] = cmService.query(new SearchPathMultipleObject(userSearchPaths), props, new Sort[]{}, new QueryOptions());

            if (bc != null && bc.length > 0)
            {
                //copy the folder to Public Folders and rename
                String[] newName={user};
                CopyOptions opt = new CopyOptions();
                opt.setUpdateAction(UpdateActionEnum.replace);
                opt.setRecursive(true);
                cmService.copyRename(bc,new SearchPathSingleObject(targetLocation),newName,opt);
            }
            else
                System.out.println("User " + user+" did not have My Folders. It could be that they have not logged on yet");
        }
        catch (Exception e)
        {
            System.out.println(e);
            e.printStackTrace();
        }
    }

    /**
     * Establish a connection to Cognos BI and initialize the different services
     */
    private void connectToCognos() 
    {
        ContentManagerService_ServiceLocator cmServiceLocator = new ContentManagerService_ServiceLocator();

        try 
        {
            cmService = cmServiceLocator.getcontentManagerService(new java.net.URL(dispatcherURL));
        } 
        catch (Exception e) 
        {
            e.printStackTrace();
        }
    }

    /**
     * Logon to Cognos BI using valid credentials information
     */
    private void logon(String nameSpaceID, String userName, String password) 
    {
        StringBuffer credentialXML = new StringBuffer();

        credentialXML.append("<credential>");
        credentialXML.append("<namespace>").append(nameSpaceID).append("</namespace>");
        credentialXML.append("<username>").append(userName).append("</username>");
        credentialXML.append("<password>").append(password).append("</password>");
        credentialXML.append("</credential>");

        String encodedCredentials = credentialXML.toString();
        XmlEncodedXML xmlCredentials = new XmlEncodedXML();
        xmlCredentials.set_value(encodedCredentials);

        try 
        {
            cmService.logon(xmlCredentials, null);
            getSetHeaders();
        } 
        catch (Exception ex) 
        {
            ex.printStackTrace();
        }
    }

    private void getSetHeaders()
    {
        String BiBus_NS = "http://developer.cognos.com/schemas/bibus/3/";
        String BiBus_H = "biBusHeader";

        BiBusHeader CMbibus = null;

        SOAPHeaderElement temp = ((Stub)cmService).getResponseHeader(BiBus_NS, BiBus_H);

        try 
        {
            CMbibus = (BiBusHeader)temp.getValueAsType(new QName (BiBus_NS, BiBus_H));
        } 
        catch (Exception e) 
        {
            e.printStackTrace();
        }

        if (CMbibus != null)
        {
            ((Stub)cmService).setHeader(BiBus_NS, BiBus_H, CMbibus);
        }
    }

    /**
     * This is the main class, which connects to Cognos BI and calls the
     * method doWork(), containing the specific code for this sample
     */
    public static void main(String args[]) 
    {

        GetOrphanMyFolders mainClass = new GetOrphanMyFolders();

        mainClass.connectToCognos();

        // If Anonymous is disabled, then logon
        if (nameSpaceID.length() > 0) 
        {
            mainClass.logon(nameSpaceID, userName, password);
        }

        //get all the CAMIDs related to the My Folders searchpath
        String[] listOfMyFolders = mainClass.getAllMyFoldersSearchPaths(nameSpaceID);
        String[][] listOfCamIds = mainClass.getAllCIs(nameSpaceID);
        Vector<String> orphanedMyFolders = new Vector<String>();

        // find a my folder that does not have an existing owner from the ldap 
        boolean found = false;
        for (int i = 0; i < listOfMyFolders.length; i++)
        {
            if (listOfMyFolders[i] != null )
            {
                if (listOfMyFolders[i].endsWith("[@name='My Folders']")) 
                {
                    int y = 0;
                    for (y = 0; y < listOfCamIds[0].length - 1; y++) 
                    {
                        String test = listOfCamIds[0][y];
                        if (listOfMyFolders[i].indexOf(test) >= 0) 
                        {
                            found = true;
                        }
                    }
                    if (!found) 
                    {
                        //  String userName = getUserNameFromCamid(listOfMyFolders[i]);
                        System.out.println(listOfMyFolders[i] + " does not have an associated user");
                        orphanedMyFolders.add(listOfMyFolders[i]);
                    }
                    found = false;
                }               
            }
        }

        // Now we need to take the list of orphaned My Folders and move them to the 
        // public folders so that the content can be examined.
        for (int x = 0; x < orphanedMyFolders.size(); x++)
        {
            mainClass.moveMF2PF(orphanedMyFolders.elementAt(x).toString(), targetLocation);
        }
        System.out.println("Done ....");
    }
}

【问题讨论】:

  • 只有这两个错误?
  • 你是如何运行程序的?你是如何设置类路径的?
  • @jrara 那么com.cognos.developer.schemas.bibus._3.PropEnum; 有问题。这就是 Oli 询问类路径的原因
  • 你导入的类,也是IBM提供的吗?如果是,您是否先编译它们,并将它们放在类路径中?
  • 您可以在 cognos 安装目录 %COGNOS_INSTALL_DIR%/c8/webapps/p2pd/WEB-INF/lib 中找到axisCognosClient.jar。编译时将此目录包含在类路径中。

标签: java sdk cognos cognos-bi


【解决方案1】:

问题是 cognos jar 当前不可见。因此,编译器无法解析对打包在此 jar 中的类的引用。

您可以在 cognos 安装目录中找到axisCognosClient.jar

 %COGNOS_INSTALL_DIR%/c8/webapps/p2pd/WEB-INF/lib 

编译时将此目录包含在您的类路径中。 此 jar 包含您在 import 语句中引用的所有类。

【讨论】:

  • 谢谢,我现在在 CLASSPATH=C:\Program Files (x86)\Java\jdk1.6.0_25\lib;C:\Program Files\ibm\cognos\c10_64\webapps\p2pd \WEB-INF\lib 但我在尝试编译时遇到同样的错误。
  • AxisCognosClient.jar 似乎在我的安装中的多个位置,但不在 webapps\p2pd\WEB-INF\lib 目录中。我将 CLASSPATH 更改为 C:\Program Files (x86)\Java\jdk1.6.0_25\lib;C:\Program Files\ibm\cognos\c10_64\sdk\java\lib 但这并没有改变这种情况。
  • 如何编译? (或者你提到的类路径在哪里被沉思?)
  • 我正在使用 javac.exe 进行编译,从命令行编译:javac.exe GetOrphanMyFolders.java。
  • 介意发布整个命令以及运行它的目录吗?
【解决方案2】:

重要的通常是最先报告的错误。修复这些将修复其余部分。如果第一个错误看起来像这样: GetOrphanMyFolders.java:19:错误:com.cognos.developer 包不存在 导入 com.cognos.developer.*; ^

然后您需要按照一些 IBM 说明下载这些包并将它们添加到您的类路径中。

如果已经下载,试试http://www-01.ibm.com/support/docview.wss?uid=swg21343429

【讨论】:

    【解决方案3】:

    您正在初始化 PropEnum 类型的属性数组。可能是 PropEnum 没有定义为属性的 canBurst 和功能。

    只是尝试删除之间的空格 {PropEnum.canBurst ,PropEnum.capabilities ,} 到 {PropEnum.canBurst, PropEnum.capabilities,}。空格应该不是问题。

    【讨论】:

      【解决方案4】:

      示例GetOrphanMyFolders.java 使用的是在Cognos 8 SDK(通常在C8_INSTALLATION_DIR/sdk/lib 下)中应该可用的外部库(即jar)中定义的类,我相信您应该寻找cognosClient.jaraxisCognosClient.jar

      由于您是 java 新手,使用 javac 编译它并将外部 jars 添加到类路径中会很麻烦。我建议你使用eclipse

      下载/安装后(只需解压缩到您喜欢的任何目录),创建一个New Java Project,在src 包下添加GetOrphanMyFolders.java(复制/粘贴或拖放)。 然后see this question 了解如何将库添加到项目类路径中。

      这将比使用javac -cp 弄清楚如何做到这一点要容易得多

      【讨论】:

        猜你喜欢
        • 2018-08-16
        • 2021-10-09
        • 2011-09-14
        • 2020-10-21
        • 2018-09-01
        • 2019-08-17
        • 1970-01-01
        • 2021-10-01
        • 1970-01-01
        相关资源
        最近更新 更多