import com.tableausoftware.TableauException;
import com.tableausoftware.common.Type;
import com.tableausoftware.extract.Extract;
import com.tableausoftware.extract.Row;
import com.tableausoftware.extract.Table;
import com.tableausoftware.extract.TableDefinition;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class TestTableau {
public static void main(String[] args) throws IOException {
//delete existing extract file
String extractFile = "extract.tde";
deleteFile(extractFile);
try (Extract extract = new Extract(extractFile)) {
//create table definition
TableDefinition tableDef = new TableDefinition();
int columnCount = 100;
for (int i = 0; i < columnCount; i++) {
tableDef.addColumn(Integer.toString(i), Type.UNICODE_STRING);
}
//create a table
Table table = extract.addTable("Extract", tableDef);
//create a sample document
//reuse the document for each row to minimize the non-tableau CPU and memory consumption
Random random = new Random();
List<String> rowData = new ArrayList<>();
for (int i = 0; i < columnCount; i++) {
rowData.add(Integer.toString(random.nextInt()));
}
long startTime = System.nanoTime();
System.out.println("Populating table...");
//populate the table
int tableRows = 4000000;
for (int i = 0; i < tableRows; i++) {
//convert input document to tableau row
Row row = new Row(tableDef);
for (int j = 0; j < rowData.size(); j++) {
row.setString(j, rowData.get(j));
}
//add the row to the table
table.insert(row);
}
long endTime = System.nanoTime();
System.out.println(String.format("Total time (ms): %s", (endTime - startTime) /
1000000));
} catch (TableauException e) {
e.printStackTrace();
}
}
private static void deleteFile(String file) {
File extractFile = new File(file);
if (extractFile.exists()) {
extractFile.delete();
}
}
}
当我运行代码时,我得到例外:
线程中的异常&#34; main&#34; java.lang.UnsatisfiedLinkError:无法 加载库&#39; TableauExtract&#39;:指定的模块不能 找到。
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:194)at at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:283)at at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:244)at at com.sun.jna.Native.register(Native.java:1065)at com.tableausoftware.extract.Extract。(未知来源)at TestTableau.main(TestTableau.java:21)
我已将以下jar文件添加到构建路径:
tableauextract.jar jna.jar tableaucommon.jar
如何解决这个问题?
答案 0 :(得分:1)
如果您的构建路径中有库,那么您是否尝试再次清理和构建项目?
答案 1 :(得分:0)
UnsatisfiedLinkError意味着您正在使用一个jar文件,该文件依赖于系统上存在的本机库,位于Java知道的位置。从您的堆栈跟踪中,我猜测您需要TableauExtract.dll(可能还有其他)。您需要的库可从Tableau站点获得:
安装完成后,需要告诉Java如何查找库文件所在的目录。此方法取决于您的操作系统,但在Unix上,您可以通过在LDLIBRARY_PATH环境变量中包含目录来实现,或者使用-Djava.library.path = flag