我正在使用JNI4net,虽然安装在构建路径和eclipse中的库识别它们,但它仍然给我运行时错误。你认为为什么会这样?这是代码。
import net.sf.jni4net.*;
import java.io.IOException;
import java.lang.String;
import system.*;
import system.Object;
import system.io.TextWriter;
import system.collections.IDictionary;
import system.collections.IEnumerator;
/**
* @author Pavel Savara (original)
*/
public class Program {
public static void main(String[] args) throws IOException {
// create bridge, with default setup
// it will lookup jni4net.n.dll next to jni4net.j.jar
//Bridge.setVerbose(true);
Bridge.setVerbose(true);
Bridge.init();
// here you go!
Console.WriteLine("Hello .NET world!\n");
// OK, simple hello is boring, let's play with System.Environment
// they are Hashtable realy
final IDictionary variables = system.Environment.GetEnvironmentVariables();
// let's enumerate all keys
final IEnumerator keys = variables.getKeys().GetEnumerator();
while (keys.MoveNext()) {
// there hash table is not generic and returns system.Object
// but we know is should be system.String, so we could cast
final system.String key = (system.String) keys.getCurrent();
Console.Write(key);
// this is automatic conversion of JVM string to system.String
Console.Write(" : ");
// we use the hashtable
Object value = variables.getItem(key);
// and this is JVM toString() redirected to CLR ToString() method
String valueToString = value.toString();
Console.WriteLine(valueToString);
}
// Console output is really TextWriter on stream
final TextWriter writer = Console.getOut();
writer.Flush();
}
}
这是我收到的消息!
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Bridge cannot be resolved
Bridge cannot be resolved
Console cannot be resolved
IDictionary cannot be resolved to a type
system cannot be resolved
IEnumerator cannot be resolved to a type
system cannot be resolved to a type
system cannot be resolved to a type
Console cannot be resolved
Console cannot be resolved
Console cannot be resolved
TextWriter cannot be resolved to a type
Console cannot be resolved
at Program.main(Program.java:37)
答案 0 :(得分:1)
为了让您的生活更轻松,我将在此分享我的发现。阅读Martin Serrano对我的问题的回答。它将帮助您了解需要完成的工作。然后转到jni4net的网站并下载他们的示例zip文件夹。提取出来。有一个例子叫myCSharpDemoCalc。用myCSharpDemoCalc.dll(在工作文件夹中)替换你的dll,然后运行generateProxies.cmd(确保将此文件编辑为你的dll名称)和run.cmd。然后转到work文件夹并运行build.cmd(编辑名称)以创建JAR文件。它可能不会吐出j4n.dll你可能需要自己修改路径。使用此JAR文件。这是从我为第三方dll创建JAR文件的最简单方法。