How can one access the combined .java file created by the IDE from multiple .pde's in a sketch

edited October 2017 in How To...

As has been discussed in other postings, the IDE concatenates multiple .pde's in a sketch into a single .java file for compilation. What I've not been able to find out (after searching on the Web for some time) is whether that .java file persists after a compilation so that, when the code throws an exception like:

    at HI_1_00$JLITable$RowPointer.setFloat(HI_1_00.java:4022)
    at HI_1_00$TextAnimationCommands.<init>(HI_1_00.java:8185)
    at HI_1_00$AnimationSelectorTable.<init>(HI_1_00.java:261)

it's possible to reference that .java file and identify the specific line in the original .pde?

Is it possible? (I'm hoping that the .java file might only get deleted at the start of a compilation, not at the end.

Thanks in advance Andy

Tagged:

Answers

  • operating system?

    processing version?

    you can export an application and the java file is in the created file (on linux at least)

  • edited November 2016

    On the Mac OS X El Capitan 10.11.6, when you export the app, the IDE creates a folder called application.macosx. Inside that, there is sketchname.app file. If you open up that "package" (in the Mac OS X sense of package, not the Java sense), in the Java folder, there is a file, sketchname.jar -- but this file appears to contain only the .class (executable byte code) file(s), not the .java source code.

    I could not see any .java files or other likely looking .jar files that might contain the source code.

    ...so it looks as though my question still stands, I'm afraid. Thanks for the reply though.

    Andy.

  • Answer ✓

    In Linux the expert creates a folder with a source folder containing original pde and processed Java file.

    The .Java file also gets created in a folder in /tmp when you compile. Have a look there. I get one or two new folders every time I compile so use ls -ltr to sort by time and check the bottom two or three.

  • (Does a Mac give you the option to export a Linux version? The mac option is greyed out when exporting from Linux in P3)

  • Yes, the Mac version of PDE 3.2.3 exports to Mac, Windows, or Linux.

  • Yay! That's it! On the Mac PDE (I happen to be still using 3.2.2), If you export to Linux, then you get a folder called application.linux-armv6hf within the sketch folder. In that there's a directory called source, and within that there is sketch.java (as well as copies of the original unconcatenated .pde's).

    The sketch.java is the concatenated output of all the .pde's in the sketch and thus appears to be the file to use when back-referencing from the unhandled Exceptions.

    Side note: there are also folders called application.linux32 and .linux64. Each of them have the sketch.java concatenated file too.

    I don't see anything that looks like the concatenated .pde's in /tmp.

    But thanks koogs/jeremy.... Whooof.... life suddenly got a whole bunch easier!

    Andy

  • edited November 2016

    application.linux-armv6hf

    this is actually the raspberry pi version. i get a 32 and 64 bit version as well. source should be the same for each.

    and now i'm on the laptop... here's a list of the files that are created at runtime in linux. i should probably put this somewhere other than here...

    i have a new sketch called tmpSound. i hit ctrl-r to run it and i get the following in /tmp

    tmpSound7424740458024084012temp/tmpSound.java - the source
    tmpSound3414582495441636571temp/tmpSound.class - the compiled class
    hsperfdata_username/ "Hot Spot" Performance data, a java thing
    161129_0493.err - stderr output, your errors
    161129_0493.out - stdout output, your println output
    

    161129_0493 is date and process id, i think. the first two are randomly named. use ls -ltr to find them.

    (mine are in /tmp but that might be because i've softlinked ~/.processing/console to /tmp so maybe look there. istr people complaining (rightly!) that tmp files are written to home partition and not cleaned up)

  • Hmmm. I hit Run, and then (at a natural pause in the sketch while it waits for me to select a file), looked in /tmp -- nothing like that, but let me do a sudo find / and see if I can see any files with names that I can identify.

    Oh....well I found them, but it's a veritable debris field of all the prior PDE "Run" commands I have done for the past several days. Specifically, the path name is: /private/var/folders/pg/ymf8g0356ts5hjclg5z7spmm0000gn/T/HI_1_007592259440945278642temp (the sketch is called "HI_1_00" so all the rest of the characters are autogenerated).

    Sooo, the good news is that's where the concatenated file went for the last Run, however, the bad news is that it will be in a different folder each time so it's a bit of a bugger to find the most recent one. I think the Linux export might be the easiest way to go, although it's tempting to write a bash script to always find the most recent .java file in /private/var/folders/pg/... and use that!

    Thanks for your help, though. One less mystery in the Universe.

    Andy

  • Just in case it's helpful for other Mac users, if you get StringOutOfBounds or NullPointer exceptions you can find the combined .java file by opening up a Terminal window and entering this command -- create the final version in a Text editor before you paste it in as you need to substitute the name of the Processing sketch you're working on:

    find /private/var/folders/pg -name 'NameOfYourSketch.java' -print0 | xargs -0 ls -atl | head -1

    Hit return and this will produce an output like this (and sorry, it's a big long line, so I deliberately split it with a backslash):

    -rw-r--r-- 1 andy staff 261416 Dec 16 15:48 **/private/var/folders/pg/\ ymf8g0356ts5hjclg5z7spmm0000gn/T/NameOfYourSketch1736464703800299330temp**/NameOfYourSketch.java

    You can check the date and time and see if it's reasonable for your last compile/run.

    Note: if for some reason your Mac account does not give you administrator privileges, then you MAY need to precede the whole command line with "sudo" to execute the command as superuser.

    sudo find /private/var/folders/pg -name 'NameOfYourSketch.java' -print0 | xargs -0 ls -atl | head -1

    Then, in the Terminal window, click and drag through the output string from "/private....temp" (the quotation marks are just for clarity!) -- you do not need to include the trailing "/" after temp. Use Command+C to copy this text onto the clipboard, switch to the Finder, and select Go -> Go to Folder. Paste the contents of the clipboard into the dialog box and click OK.

    The Finder should then open up a window with NameOfYourSketch.java in it and you can use the text editor of your dreams to inspect the source file that is causing the error. I find that, generally speaking, if you look at the Exception stack trace, it's the second line that's the most useful:

    java.lang.StringIndexOutOfBoundsException: String index out of range: -1
        at java.lang.String.substring(String.java:1967)
        at NameOfYourSketch$ClassName.<init>(NameOfYourSketch.java:332)
    

    It's that second line number, 332, that's often the most probative in terms of finding the problem.

    Hope this helps someone on a Mac.

    Oh...if you leave the Terminal window open, and need to repeat the above process, just enter a command of "!!" (two exclamation marks) to get the bash shell to repeat it.

    If you want to see more of the available .java files for your sketch, change the "head -1" to, meh, "head -5".

    Andy

  • Thanks so much for sharing this solution, @ajohnsonlaird.

    For others, please note that:

    1. This path structure may be specific to MacOS.
    2. Your subfolder will vary. The example given is to search /private/var/folders/pg, but on my machine the temp files are currently found in /private/var/folders/f7. Best to just search /private/var/folders/.
  • All valid points, Jeremy. It was not clear how much of the file path was random and how much was predetermined -- so you're quite right in suggesting the command line be corrected so that it does not assume the immediately superordinate subdirectory (pg for me, f7 for you).

    I've included it below in its entirety so it can be subject to copy and pastry [sic].

    sudo find /private/var/folders/ -name 'NameOfYourSketch.java' -print0 | xargs -0 ls -atl | head -1

    Thanks for pointing this out. Andy

  • edited October 2017

    I've tweaked the Terminal command line above to automagically start up the Sublime Text 3 editor on the Java file so that I can proceed directly to the line causing a Null Pointer exception (or whatever misfortune leads you to need to see the concatenated .java file! :) ). The command line is:

    sudo find /private/var/folders -name '*.java' -print0 | xargs -0 ls -1t | head -1 | xargs /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl

    This code:

    1. Executes the find command to locate the concatenated .java file.

    2. Uses the print0 option on the find command to put it a format for xargs.

    3. Xargs then feeds it into the ls command to output the possible .java files as a series of file paths and names, sorting the newest one to be first.

    4. That output is then fed into the head command to take only the first line.

    5. That first line (the newest .java file) is then fed into the command line invocation of the Sublime text editor which then opens up the concatenated .java file.

    As before Jeremy's comments remain valid so that's why the find command searches /private/vars/folders.

    Hope this helps (and apologies it's Mac only -- I've tested it on Mac OS Sierra). A modified version might work on Linux, though.

    Cheers Andy

  • @ajohnsonlaird -- thank you for this, Andy.

    For TextMate users on Mac, this similar command also worked for me:

    sudo find /private/var/folders -name '*.java' -print0 | xargs -0 ls -1t | head -1 | xargs mate
    

    Note that you may then be asked to type in your admin password in order to use sudo (for listing and open files in /private).

    To scroll directly to the offending Line -- e.g. line 40 -- append -l 40:

    sudo find /private/var/folders -name '*.java' -print0 | xargs -0 ls -1t | head -1 | xargs mate -l 40
    
Sign In or Register to comment.