// Create the SdeWorkspaceFactory
try {
SdeWorkspaceFactory sdeFact = new SdeWorkspaceFactory();
// Create a PropertySet object that will contain all of the
// SDE connection parameters
PropertySet propSet = new PropertySet();
// Populate the property set with the connection parameters
propSet.setProperty("SERVER", "192.168.222.128");
propSet.setProperty("INSTANCE", "5151");
propSet.setProperty("DATABASE", "sde");
propSet.setProperty("USER", "sde");
propSet.setProperty("PASSWORD", "sde");
propSet.setProperty("VERSION", "sde.DEFAULT");
// Open the ArcSDE workspace using the connection PropertySet
Workspace ws = new Workspace(sdeFact.open(propSet, 0));
// Get the collection of dataset names in the database and display their names
IEnumDatasetName dsNames = ws.getDatasetNames(esriDatasetType.esriDTAny);
IDatasetName name = dsNames.next();
while (name != null) {
System.out.println(name.getName());
name = dsNames.next();
}
} catch (IOException e) {
e.printStackTrace();
}
总是报错误
Could not load native libraries. ArcGIS/bin should be added to the system PATH environment variable.
java.lang.UnsatisfiedLinkError: no ntvauth in java.library.path
java.lang.UnsatisfiedLinkError: no ntvauth in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682)
at java.lang.Runtime.loadLibrary0(Runtime.java:822)
at java.lang.System.loadLibrary(System.java:993)
at com.esri.arcgis.interop.NativeLoader.loadLibrary(Unknown Source)
at com.esri.arcgis.interop.NativeAuth.c(Unknown Source)
at com.esri.arcgis.interop.c.a(Unknown Source)
at com.esri.arcgis.interop.bc.a(Unknown Source)
at com.esri.arcgis.interop.jb.a(Unknown Source)
at com.esri.arcgis.interop.Dispatch.createDispatch(Unknown Source)
at com.esri.arcgis.interop.Dispatch.<init>(Unknown Source)
at com.esri.arcgis.geodatabase.IWorkspaceFactoryProxy.<init>(Unknown Source)
at com.esri.arcgis.datasourcesGDB.SdeWorkspaceFactory.<init>(Unknown Source)
at com.esri.arcgis.datasourcesGDB.SdeWorkspaceFactory.<init>(Unknown Source)
at com.dist.FlexGIS.Operation.main(Operation.java:24)
查找了很多资料,有人说需要把ntvauth.dll加到path环境变量中,但是我没有找到ntvauth.dll,请高手赐教ntvauth.dll 在什么位置,需要装什么软件吗,我已经安装了server(java),engine(java,。net)和sde了。
解决方案:
把Server初始化一下就可以了
提供一个参考代码
ServerInitializer serverInitializer = new ServerInitializer();
serverInitializer.initializeServer("workgroup", "arcgismanager", "1");
ServerConnection connection = new ServerConnection();
connection.connect("192.168.222.128");
IServerObjectManager som = connection.getServerObjectManager();
IServerContext context = som.createServerContext("HY","MapServer");
// Create a PropertySet object that will contain all of the
// SDE connection parameters
IPropertySet propSet = (PropertySet)context.createObject(PropertySet.getClsid());//new PropertySet();
// IPropertySet propSet = new PropertySet();
// Populate the property set with the connection parameters
propSet.setProperty("SERVER", "192.168.222.128");
propSet.setProperty("INSTANCE", "5151");
propSet.setProperty("DATABASE", "sde");
propSet.setProperty("USER", "sde");
propSet.setProperty("PASSWORD", "sde");
propSet.setProperty("VERSION", "sde.DEFAULT");
IWorkspaceFactory sdeFact = (IWorkspaceFactory)context.createObject(SdeWorkspaceFactory.getClsid());//new SdeWorkspaceFactory();
//IWorkspaceFactory sdeFact = new SdeWorkspaceFactory();
// Open the ArcSDE workspace using the connection PropertySet
IWorkspace ws = sdeFact.open(propSet, 0);
//Workspace ws = new Workspace(sdeFact.open(propSet, 0));
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)ws;
IWorkspaceEdit eWorkspace = (IWorkspaceEdit)ws;
IFeatureDataset featureDataset = featureWorkspace.openFeatureDataset("ZT_HY");
IWorkspace workspace = featureDataset.getWorkspace();
IFeatureWorkspace fWorkspace = new IFeatureWorkspaceProxy(workspace);