我正在使用Rust 1.0 beta并且能够创建一个小例子来调用从Java编写的Rust函数.我只是使用rustc在mylib.rs中编译以下Rust代码,在Windows上生成mylib.dll:
#![crate_type = "dylib"]
use std::any::Any;
#[no_mangle]
pub extern fn Java_tests_Test_hello(env: *const Any, jclass: *const Any) {
println!("hello from rust");
}
#[no_mangle]
pub extern fn Java_tests_Test_sum(env: *const Any, jclass: *const Any, a: i32, b: i32) -> i32 {
return a + b;
}
Run Code Online (Sandbox Code Playgroud)
然后我可以从Java类test.Test调用这些函数:
package tests;
import java.io.File;
public class Test {
public static native void hello();
public static native int sum(int a, int b);
public static void main(String[] args) {
File f = new File("mylib.dll");
System.load(f.getAbsolutePath());
Test.hello(); …Run Code Online (Sandbox Code Playgroud) 我想简单地使用java.util.Logging登录控制台:
Logger log = Logger.getLogger("my.logger");
log.setLevel(Level.ALL);
ConsoleHandler handler = new ConsoleHandler();
handler.setFormatter(new SimpleFormatter());
log.addHandler(handler);
log.fine("hello world");
Run Code Online (Sandbox Code Playgroud)
但这没有打印出来.我错过了什么?
谢谢
是否可以使用标准JPA 2在相应实体表的单个字段中存储整数列表?
就像是:
@Entity
@Table(name="tbl_myentities")
public class MyEntity {
@ElementaryCollection
@Column(name="vals") // in table tbl_myentities
private List<Integer> vals;
Run Code Online (Sandbox Code Playgroud)
谢谢
已经有一个问题,但与Rust 0.13有关,语法似乎已经改变.从当前文档中我了解到在堆上创建数组将是这样的:
fn main() {
const SIZE: usize = 1024 * 1024;
Box::new([10.0; SIZE]);
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行这个程序时,我收到以下错误:
thread '<main>' has overflowed its stack
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
是否有可能null在Java中的引用上创建方法引用
?这样做可能永远不会正确,但可能导致以后很难找到的错误:
public class Test {
void m() {
}
public static void main(String[] args) {
Test test = null;
Runnable fn = test::m; // no exception
System.out.println(fn); // prints Test$$Lambda$1/791452441@1c20c684
fn.run(); // throws a null pointer exception
}
}
Run Code Online (Sandbox Code Playgroud) 有关加载共享库和使用Windows上的syscall包调用函数的非常好的描述(https://github.com/golang/go/wiki/WindowsDLLs).然而,功能LoadLibrary和GetProcAddress那些在本说明中使用未在系统调用封装在Linux上使用.我找不到关于如何在Linux(或Mac OS)上执行此操作的文档.
感谢帮助
我有几个域类的描述符类.描述符类有一个字段'type',它是一个枚举,表示域类的类型.在某些查询中,我想返回或更多描述符,并将类型作为构造函数参数传递.所以我的想法是将它作为查询参数传递:
String jpql = "SELECT NEW model.ModelDescriptor"
+ "(t.id, t.name, t.description, :modelType) ... ";
TypedQuery<ModelDescriptor> query = em.createQuery(jpql, ModelDescriptor.class);
query.setParameter("modelType", ModelType.forClass(clazz));
List<ModelDescriptor> list = query.getResultList();
Run Code Online (Sandbox Code Playgroud)
这不起作用.没有抛出异常,但类型null在结果中.此外,无法将枚举文字传递给查询:
"SELECT NEW model.ModelDescriptor (f.id, f.name, f.description,
model.ModelType.FLOW) ... "
Run Code Online (Sandbox Code Playgroud)
编辑 我得到以下堆栈跟踪:
java.lang.IllegalArgumentException: An exception occurred while creating a query in
EntityManager:
Exception Description: Error compiling the query [SELECT model.ModelDescriptor(f.id,
f.name, f.description, model.ModelType.FLOW) FROM Flow f WHERE flow.id = :flowId],
line 1, column 78: unknown identification variable [model]. The FROM clause of the …Run Code Online (Sandbox Code Playgroud) 像Java,C#等。我如何enum Direction { input, output }在Smalltalk中定义类似的东西?
是否可以将 64 位 XulRunner for Windows(可从此处获得)与 Eclipse 浏览器小部件一起使用?它在 32 位 Windows 下工作正常,这个问题的答案解释了它是如何工作的。但是当我在 64 位 Windows 下尝试这个时,我得到以下异常:
org.eclipse.swt.SWTError: No more handles (java.lang.UnsatisfiedLinkError: Could not
load SWT library. Reasons:
no swt-xulrunner-win32-3834 in java.library.path
no swt-xulrunner-win32 in java.library.path
Can't load library:
C:\Users\...\.swt\lib\win32\x86_64\swt-xulrunner-win32- 3834.dll
Can't load library: C:\Users\...\.swt\lib\win32\x86_64\swt-xulrunner-win32.dll
at org.eclipse.swt.SWT.error(SWT.java:4387)
at org.eclipse.swt.SWT.error(SWT.java:4276)
at org.eclipse.swt.browser.Mozilla.initXULRunner(Mozilla.java:2594)
at org.eclipse.swt.browser.Mozilla.create(Mozilla.java:684)
at org.eclipse.swt.browser.Browser.<init>(Browser.java:99)
at org.openlca.ui.BrowserFactory.createMozilla(BrowserFactory.java:52)
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助,迈克尔
编辑: 我在 Eclipse 错误跟踪器中找到了它(链接在这里):
swt 的 64 位 Windows 端口没有 xulrunner 支持,因为 mozilla.org 不提供 Windows 上的 64 …
我目前正在阅读这样的文件:
dir := FileSystem disk workingDirectory.
stream := (dir / 'test.txt' ) readStream.
line := stream nextLine.
Run Code Online (Sandbox Code Playgroud)
这在文件被utf-8编码时有效,但当文件有另一种编码时我无法找到该怎么做。
java ×6
pharo ×2
rust ×2
smalltalk ×2
arrays ×1
eclipse ×1
eclipse-rcp ×1
eclipselink ×1
go ×1
heap ×1
java-8 ×1
jpa ×1
jpa-2.0 ×1
jpql ×1
null ×1
spring-boot ×1
swt ×1
system-calls ×1
xulrunner ×1