Include the files from the data directory in Eclipse, and have it working in Exports

edited September 2015 in How To...

Hello

My processing project in Eclipse is using a txt file to store stuff. it all works ok until I try to Export the application. The process creates the "application.linux/", "application.macosx/" and "application.windows/" folders with the application things in it but my txt file is not there.

I did try what was propose here*, didn't work any better. I did with my txt file in a data/ folder in src/, with the txt file in a data/ folder at root level and with the txt file simply dropped at root level. No better luck

any idea ?

cheers

*https://processing.org/discourse/beta/num_1209991253.html "Here's how I got it Eclipse to include the files from the data directory at runtime :

  • if it isn't there already, copy/create the data directory into your Eclipse project (on the same level as the src dir)

so

myProject |src |__data |____file1.ext |____file1.ext |____... |...

  • refresh your project in Eclipse (RMB -> Refresh, or F5). You should now see the data dir and its contents reflected in Eclipse.

  • make Eclipse aware that it has to include the files at runtime: Eclipse -> Run menu -> Run Configurations -> Classpath -> User Entries -> Advanced -> Add Folders -> select the data dir"

Answers

  • @phoebus=== though i cannot see why you are using eclipse + processing, which is useless for 90% / cases,if you do that, you must put your files (.txt, .mp3...) in the data folder in src, root. Then, don't think that this "data" dir is "known" as the processing "data" folder. Get its path as a global (at the very beginning, something like dataPath(""); and in your code use it!! _if you don't you can add some log to see WHERE your app is looking for your files:: surprise (depends of OS but not at all like you work with processing and nothing more...)

  • thank you for the answer

    this must be the solution but I have to figure out the "Get its path as a global (at the very beginning, something like dataPath(""); and in your code use it!!" part...

    If I say what I think this phrase means I will be considered a moron, so I prefer just to say that I didn't get it... and hope there will remain some uncertainty about my intelligence :]

  • edited September 2015
        import java.io.File;
        import java.io.IOException;
        public static String myPathToDataFolder;
    
        public void setup(){
        size(800,600);
        String myPathToDataFolder = dataPath("");
        println(myPathToDataFolder);
    
        }
    

    in order to see where it is looking for :

         try{
         File file = new File(".");  
         File[] files = file.listFiles();  
        System.out.println("Current dir : " + file.getCanonicalPath());
        for (int fileInList = 0; fileInList < files.length; fileInList++)  
         {  
        System.out.println(files[fileInList].toString());  
               }
         }catch(IOException ex){
         }
    
  • edited September 2015

    this is what I get :

    C:\Users\Rich\workspace\Richy_PROJECT\data
    Current dir : C:\Users\Rich\workspace\Richy_PROJECT
    .\.classpath
    .\.project
    .\.settings
    .\application.linux
    .\application.macosx
    .\application.windows
    .\bin
    .\data
    .\Diagram.ajsv
    .\Levels - ORI.txt
    .\levels.dat
    .\Levels.txt
    .\lib
    .\preferences.txt
    .\src
    

    Does that means it doesn't look for the data/ folder inside the src/ folder ?

    I think I am understanding a bit: - once, using this dataPath("") function that is part of the java.io.File, I get the Path that my project is using. - The I should specify this very path when I'm adressing a file from my data folder.

    Does that means I cannot change it to be inside the src/ folder ?

    Will it solve itself when making a export folder of my project ?

  • that means that it s looking into your main project folder; are your files at that level??? -

  • right now my data.txt file is at root, but I would like to put it wherever it would take it into account for the export

  • data.txt is the file name??? i cannot see it in your post...

  • I said data.txt to mean the file with my data. But the actual name is Levels.txt

  • ok, so it sees your file "Levels.txt" try to make some method for reading (create reader()) this file in the console what happens???

  • Did I mention that my code runs flawlessly from Eclipse ? It is just that , when I export it using the processing export button, it doesn't export the Levels.txt file, and therefor doesn't work. And no matter where I drop the file inside the exported forlder, it doesn't take it into account

  • @phoebus:: Are you using proclipsing for exporte? - AFTER the export was done if you put your Levels.txt near the .app in the same folder what happens?

  • edited September 2015

    @phoebus:: well, instead of asking, now that i think to understand your problem i shall take an example (very simple!!!)

    i write this code in eclipse (of course all imports are done, i have the jars in my libs && build path, core.jar && others (depending of your OS: windows, linux, mac); the code uses a .txt file here called save.txt (like your Levels.txt); this file is in the data dir, at the same level than the source or libs folder. The code::

        package com.akenaton.ExportDataEclipse;
    
        import processing.core.PApplet;
    
        public class ExportDataEclipse extends PApplet implements Runnable {
    
    
        String leTxt;
        public void setup(){
    
            this.size(800,600);
            this.background(0);
            String[] temp=loadStrings("save.txt");
            leTxt = temp[0]; 
            textSize(24);
            fill(255);
            text(leTxt, 400,300);   
        }
    
        public void draw(){
    
            this.background(0);
    
            this.text(leTxt, 400,300);  
        }
    
    
        public static void main(String _args[]) {
        PApplet.main(new String[] { ExportDataEclipse.class.getName() });
        }
    
        }
    

    Simple, as you can see...

    Second step: run configuration, set the main etc: launch, everything works fine

    Third step::: export as an app, for my OS (OSX)

    a) as the other one you have written about in your first post:: i run configuration, advanced, add folder:: here i add my data folder. b) export:: i dont choose "runnable jar", i go to "other" and here i choose mac osX c) click finish try the .app it creates (where you have decided to put) As for me it works... What i dont know is: with the same method can i export for other OS??? I think so because native P5 can do that and proclipsing also but i never tried. Perhaps adding windows && linux jars???

    tell me the result for you

  • Yes I use Proclipsing. To export my project I go to Project -> Processing Export then I choose application and finish... Then I get 3 folders, one for each OS, none of which include my Levles.txt file

  • I just saw your previous post (my last answer dates from before)

    I work on Windows7. Also, might my problem come from the fact that I export as application instead of Applet ? When I test I run as application and all is fine.

  • have you tried with my step_by_step??? if you use proclipsing have you tried to put your ap+Levels.text into the same folder after exporting? application is not the problem.

  • @phoebus:: i have tried with proclipsing also and it works... (text file in data at the root level)

  • @phoebus::: are you sure that you a) put your files in data (procssing standard folder) at root level b) put these files also in the src folder in a subfolder data??? --- i have tried with && without adding advanced folder:: it works in any case

  • is it possible to chat with you ? I get

    Exception in thread "Animation Thread" java.lang.ArrayIndexOutOfBoundsException: 0

  • so I put some text in the save.txt and the program runs good

    I try to export , it create the application.linux but it gives me this error

    [ERROR] The size of this applet could not automatically be determined from your code. Use only numeric values (not variables) for the size() command. See the size() reference for an explanation. Exception: null :: java.lang.reflect.InvocationTargetException

  • edited September 2015

    @phoebus: classic error; i suppose you have coded something like:

        public void setup(){
    
        PImage img = loadImage("monImage.jpg");
        int w= img.width;
        int h = img.height;
        size(w, h);
        // this code does not work...NPE::::: size must be se at the very beginning of your sketch;
        }
    

    think to put answered for others (your first problem is often asked for)

    • I'm am using the code you gave me, so, the size part is at the begining of setup

    • So I cannot tell if the export work since I cannot complete the export process

  • edited September 2015

    Ok, here is the solution:

    • 1) Put the data/ folder of your Eclipse/Processing project at root level (which means same level as lib/, src/, bin/...

    • 2) make Eclipse aware that it has to include the files at runtime: Eclipse -> Run menu -> Run Configurations -> Classpath -> User Entries -> Advanced -> Add Folders -> select the data dir"

    • 3) in your code, the path to your file shall be like this: "data/myText.txt" or "data/myImage.jpg"...

    • 4) Use the "Processing Export" button to create your OS specific application folder

    • 5) last BUT NOT LEAST, _make a copy of your data/ folder inside the OS specific application folder _

    On Windows, your start your application by launching the myProject.bat

    ps: is there a way the get rid of the DOS window while your Processing application is running ? may be change that line:

    @echo off java -Djava.ext.dirs=lib -Djava.library.path=lib myproject.myPROJECT

    pps: thank you akenaton for your help

Sign In or Register to comment.