3

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

What steps should I follow to get the following code to work (in Consumer.java)

My basic setup looks like that:

I installed the eclipse-plugin and followed the instructions.

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:

module FregeProducer where

myZero = 0 
Cirquit
  • 464
  • 2
  • 9

1 Answers1

2

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.

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.

You need to specify the module name as tutorials.FregeProducer. (It is not enough to merely place the source file in the tutorials directory.) Then your unaltered Java code should work, IMHO.

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
Ingo
  • 36,037
  • 5
  • 53
  • 100
  • When I tried to add a package declaration to FregeProducer it still could not resolve the dependencies. Unfortunately the second method also did not work for me. I created a new package namely "fregepkg", moved FregeProducer and renamed it "fregepkg.FregeProducer". It worked with the same setup with the .java-Files :( – Cirquit Jul 22 '15 at 22:59
  • @Cirquit hmm. I need to investigate this further. It should work, but your previous attempt could not possibly work. – Ingo Jul 23 '15 at 06:54
  • @Cirquit apparently, it works only when one adds the bin/ directory to the Build Path as an "External Folder". Eclipse will still not pick up the FregeProducer.class file until you have refreshed the bin/ directory in the Navigator-View. Perhaps it is better to have the Frege Files in a separate Project and reference them from the Java-only project? – Ingo Jul 24 '15 at 21:51
  • It works as you described! If I add the bin/ directory (under another name, because else he won't accept it) it sees the constants. I will have a go with the project idea, when this won't suffice anymore for my basic examples! Thank you for your help! – Cirquit Jul 26 '15 at 11:39