简体   繁体   English

如何在Eclipse中从Java调用Frege?

[英]How to call Frege from Java in Eclipse?

I couldn't find a single out-of-the-box example on this topic. 我在这个主题上找不到一个开箱即用的例子。

I succeeded in calling from Frege to Frege, as well as from Java to Java in the same project, but I couldn't get the .java-files to recognize the .fr-files 我成功地从Frege到Frege,以及在同一个项目中从Java到Java调用,但是我无法让.java文件识别.fr文件

What steps should I follow to get the following code to work (in Consumer.java) 我应该遵循哪些步骤来使以下代码起作用(在Consumer.java中)

My basic setup looks like that: 我的基本设置如下:

I installed the eclipse-plugin and followed the instructions. 我安装了eclipse-plugin并按照说明操作。

java version "1.7.0_79"

Project Builders in the following order: 项目构建器按以下顺序:

Frege builder
Java Builder

Project path: 项目路径:

* src
      - package tutorials
        -- Consumer.java
        -- FregeProducer.fr

* Referenced Libraries
      - fregec.jar

* JRE System Library
      - ...

Consumer: 消费者:

package tutorials;

public class Consumer {

    public static void main(String[] args) {
        System.out.println("This should be zero: " + FregeProducer.myZero);
    }   
}

FregeProducer: FregeProducer:

module FregeProducer where

myZero = 0 

Your setup is all right, as far as I can see. 就我所见,你的设置是可以的。 However, it looks like you are running into a Java restriction that does not allow to use classes from the unnamed package in a class that is in a named package. 但是,您似乎遇到了Java限制,该限制不允许在命名包中的类中使用未命名包中的类。

What we have here is an attempt to use something in class FregeProducer from within tutorials.Consumer and this is not going to work by Java rules. 我们在这里尝试在tutorials.Consumer使用类FregeProducer某些东西,这不适用于Java规则。

You need to specify the module name as tutorials.FregeProducer . 您需要将模块名称指定为tutorials.FregeProducer (It is not enough to merely place the source file in the tutorials directory.) Then your unaltered Java code should work, IMHO. (这是不够的,仅仅放置在源文件tutorials目录。)然后你不变的Java代码应工作,恕我直言。

You can, of course, produce Frege classes in any package you want. 当然,您可以在任何所需的包中生成弗雷格类。 For this, you need to move the source file in the corresponding directory and choose an appropriate module name. 为此,您需要将源文件移动到相应的目录中,然后选择适当的模块名称。 Remember that the module name (and only the module name, and neither the source file name nor location) determines the fully qualified class name of the compiled class: 请记住,模块名称( 只有模块名称,源文件名和位置)都不能确定已编译类的完全限定类名:

module Foo where    -- creates class Foo in unnamed Java package
module com.bar.Foo where -- creates class Foo in Java package com.bar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM