与Haxe中的Java函数进行接口 [英] Interfacing with Java Functions in Haxe

查看:67
本文介绍了与Haxe中的Java函数进行接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用"extern"从Haxe调用外部Java函数.

I am trying to call an external Java function from Haxe using "extern".

哈希码:

extern class Ext
{
   public static function test():String;
}

class Sample 
{
   public static function main()
   {
       trace(Ext.test());
   }
}

Java代码:

public class Ext
{   
    public static String test()
    {
        return "Hello";
    }
}

Sample.hx和Ext.java文件都在同一文件夹中.

Both Sample.hx and Ext.java files are in the same folder.

当我尝试执行 haxe -main Sample -java Sample 时,出现以下错误.

When I try to execute haxe -main Sample -java Sample, I get the following error.

C:\Users\ila5\Desktop\CPP>haxe -main Sample -java Sample
haxelib run hxjava hxjava_build.txt --haxe-version 3201 --feature-level 1
javac.exe "-sourcepath" "src" "-d" "obj" "-g:none" "@cmd"
src\haxe\root\Sample.java:33: error: cannot find symbol
                haxe.Log.trace.__hx_invoke2_o(0.0, haxe.root.Ext.test(), 0.0, new haxe.lang.DynamicObject(new java.lang.String[]{"className", "fileName", "methodName"}, new java.lang.Object[]{"Sample", "Sample.hx", "main"}, new java.lang.String[]{"lineNumber"}, new double[]{((double) (((double) (10) )) )}));
                                                            ^
  symbol:   class Ext
  location: package haxe.root
1 error
Compilation error
Native compilation failed
Error: Build failed

我想了解为什么构建失败.有任何想法吗?

I would like to understand why the build failed. Any ideas?

推荐答案

我不确定您可能需要使用-lib或其他方式引用Java代码吗?

I am not sure you might need to reference your Java code with -lib or something else?

但是通常对于Java目标,仅使用jar文件要简单得多.通过输入haxe --help,您将看到列出的相关命令,而我不需要为Java目标手动编写外部代码.

But generally with Java target it's much simpler to just use a jar file. By typing haxe --help you will see the relevant command listed, I have never had a need to hand write externs for the Java target.

-java-lib <file>:添加一个外部JAR或类目录库

-java-lib <file> : add an external JAR or class directory library

这篇关于与Haxe中的Java函数进行接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆