Where can I edit contributed library source code?

edited January 2016 in Library Questions

I'm using Minim library and I need to do one of two things: I need to either extend a class in the library, or make some alterations to the minim source code. The problem is: I have no idea how to start a new project in the processing environment so I can extend the class, and I have no idea where the source code is located. I searched through the processing folder in my file system, but it found no instances of Minim. Help please?

Answers

  • If you've got (or once you've got) Minim installed, go to your sketchbook folder, where all ".pde" sketches go into, and look for the subfolder "library/" there.
    Minim's ".java" source code path is: "\libraries\minim\src\ddf\minim"

    You can also look for its API online here: http://code.Compartmental.net/minim/
    And also its source code @: https://GitHub.com/ddf/Minim/tree/master/src/ddf/minim

  • Followed your instructions to a T. Found the sketchbook folder, went into libraries, went to minim, went to src, went to ddf, went to minim and edited a java file, saved it, yet still it doesn't register any changes. Is it because I'm editing the java files in eclipse? Should I be using processing?

  • ".java" files, just like ".pde" 1s, are just human-readable text.
    They still need to be compiled in order for our machines to run it.
    In case of ".java", they become ".class" files compressed inside ".jar" files.

  • Right well eclipse compiles on the fly so that's no problem. Still not sure why this isn't working.

  • edited January 2016
    • You still have to modify the whole "minim.jar" file from path "\libraries\minim\library\"!
    • Let's say you've changed "Minim.java" and successfully compiled it as "Minim.class".
    • Then you replace the original "Minim.class" inside "minim.jar" w/ your own hacked 1.
  • OK, what your saying doesn't make any sense to me at all. This is my first personal coding project outside of school, so if I'm "not getting it", please forgive. What's not making sense is that a JAR file is an executable. How I'm I supposed to alter binary code? Further, you're telling me to compile my java file into a class file so I can put it in my jar file, but I don't see the class files anywhere in the minim directory. You see where I'm having trouble yet?

  • edited January 2016

    ... you're telling me to compile my java file into a class file...
    ... Eclipse compiles on-the-fly so that's no problem.

    I haven't told you anything! You said there was no problem to compile; so I've just assumed that you did!
    I'm noticing that you're spilling more tiny details bit by bit on each post.
    But we can only reply based on the information you've provided thus far. We're not psychics! 8-X

    What's not making sense is that a JAR file is an executable.

    The ".class" files inside a ".jar" file are the actual executables.
    Java's VM machine interprets those bytecode ".class" files into machine code on-the-fly.
    As mentioned before, ".java" files become ".class" files after the former are compiled by the "javac.exe".

    How I'm I supposed to alter binary code?
    I need to either extend a class in the library, or make some alterations to the Minim source code.

    It was your own idea. I'd only recommend such "drastic" approach after everything else had failed! :-\"
    Your 1st approach should be to incorporate your changes into an extended subclass.

    Failing on that (or in addition to that), you could request the library devs to include those extra features directly in the official release.

    Hacking the library by changing some ".java" file, then compiling it as ".class", then replacing the original ".class" inside the ".jar' w/ that, demands a very good Java knowledge! ~O)

  • Oh so you do this all day to feel good about yourself? I see. Yes, you're certainly better than me. Thanks so much for your help.

  • edited December 2016

    If making a subclass doesn't work for some reason, you can open up the source code in your favorite java code editor and make the changes. Then compile it to .class. If your java code editor doesn't have that feature, the easiest way is (on Windows) to browse to the .java file in explorer, shift-right click anywhere in the folder, click "Open command prompt here" then type "javac classname.java". This should run the java compiler and produce a .class file. You can then open the .jar file using Winrar for example (on my computer you can right click a .jar file, select "Open with" and choose Winrar or another compression program that can open .jar files). Then drag and drop the .class file and replace the original one.

    But I must say... if GoToLoop's explanations went over your head... it might be this approach is just not what you really need to do.

  • edited January 2016

    ... click "Open command prompt here" then type "javac classname.java".

    Unfortunately, the JDK installation for Windows doesn't set the %PATH% variable to "javac.exe".
    Until we do it ourselves, we can't call "javac.exe" unless we specify its full path:
    %ProgramFiles%\Java\jdk1.8.0_72\bin\

    http://www.Oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
    http://download.Oracle.com/otn-pub/java/jdk/8u72-b15/jdk-8u72-windows-x64.exe

  • This is a quick question following @coloredmirrorball's latest post:

    This should run the java compiler and produce a .class file. You can then open the .jar file using Winrar (...)

    Is it possible to generate the actual jar file instead of opening the original one and rewriting its original class file with the altered generated class version?

    Adding to this, could you generate a class file (jar file?) from Eclipse directly?

    Third question, to generate class files, you need the JDK or ca you do it using only JRE?

    Kf

  • edited December 2016

    @kfrajer As far as I know, you need JDK to generate the .class files from .java files. JRE is just the Runtime Environment, so I very much doubt if it could convert the high-level code into Java bytecode.

    And, again AFAIK, you can generate a .class file in Eclipse if you have the required .java file.(If you can't find a way, just search the workbook folder of Eclipse on your computer).

    And you probably can generate .jar files (using Eclipse, or if you like remaining away from IDE's, then using the command line), but only if you first generated the .class files.

    P.S. I may have made some mistakes, so if anyone knows better, please correct me.

  • As you have discovered the solution to modifying a contributed library is challenging if not difficult.

    There is an easier solution and that is too create a library template project for minim in Eclipse and use the ant build script to create the library jars. Then you can edit the source code and build the library quickly and as often as you want.

    Of course this is not as straightforward as it sounds, especially if you have never done something like this before. So hopefully I can make it simpler still ;)

    Step 1
    In your Eclipse workspace (where your projects are stored) and create a folder called libs. Locate Processing's core.jar file and copy it into this new folder. The file location will depend on your OS

    Step 2
    Download the file minim.zip from DropBox. This file is an archived Eclipse project containing minim which I created earlier just for this purpose.

    Step 3
    In Eclipse select File > Import from the menus, In the dialog box open the General tab and select Existing Projects into Workspace and click next. In the next dialog box choose the Select archive file and browse to the minim.zip file you just downloaded. Click on Finish and a new project will be created and appear in Eclipse called 'Minim'

    Step 4
    Right click on the in the Project Explorer window right click on the project name (Minim) and from the popup-menus select Build Path > Configure Build Path. In the dialog box click on the Libraries tab.

    buildpath Two of the entries probably have red crosses beside them . The first is core.jar, select it and then click Edit and browse to the one you created in step 1. The other is the last one is JRE System Library again click on edit and select a JDK on your system. On WIndows and Linux they are likely to be listed as JDKs on Osx they are listed as JREs

    Step 5
    In the Minim project there is a folder called Resources, expand this and you will see a file called build.properties, right click on this and select open with "Properties File Editor". You need to change lines 19 and 32 to the paths used on your system.

    Step 6
    In Eclipse look at the right hand pane where you have the Outline view. If you can't see a tab called Ant then go to the Windows menu and select Show View > Ant and it will appear alongside the Outline tab. Now in the Resources folder drag the file build.xml into the Ant pane and a new entry called Minim Custom will appear.

    WOW nearly there

    Step 7
    Hopefully the last step. In the Ant view double click on "Minim Custom" and it will not only build the minim library but set it up correctly in your sketch folder. It took 22 seconds to build on my system so be patient. The console window shows the progress made. You may get an error during the build, if you do don't panic just paste the last 10 lines from the console here and I will see what I can do.

    Whenever you are doing something like this for the first time it can be a bit nerve racking. The trick is to take your time and make sure you have completed each step before starting the next. I suggest that you print this comment out so you can have it beside you when you do it.

    Good luck! :)

  • Wow, really detailed post from @quark.

  • @quark I second Lord on your post. Thank you.

    Just adding to this discussion, processing can generate class files if one uses the command line option, adding to the comment made by @colouredmirrorball on Jan 26th:

    processing-java.exe --help

    Command line edition for Processing 0251 (Java Mode)

    --help Show this help text. Congratulations.

    --sketch= Specify the sketch folder (required)
    --output= Specify the output folder (optional and
    cannot be the same as the sketch folder.)

    --force The sketch will not build if the output
    folder already exists, because the contents
    will be replaced. This option erases the
    folder first. Use with extreme caution!

    --build Preprocess and compile a sketch into .class files.
    --run Preprocess, compile, and run a sketch.
    --present Preprocess, compile, and run a sketch in presentation mode.

    --export Export an application.
    --no-java Do not embed Java. Use at your own risk!
    --platform Specify the platform (export to application only).
    Should be one of 'windows', 'macosx', or 'linux'.

    The --build, --run, --present, or --export must be the final parameter passed to Processing. Arguments passed following one of those four will be passed through to the sketch itself, and therefore available to the sketch via the 'args' field. To pass options understood by PApplet.main(), write a custom main() method so that the preprocessor does not add one. https://github.com/processing/processing/wiki/Command-Line

  • @kfrajer -- are you saying that class files generated through the command line can then be added to the Library folder, allowing Projammin to use PDE to make a Library?

  • @jeremydouglass I am referring to the --build option in my previous post.

    Nop, the processing-java generates the ".class", no the ".jar". I haven't tested this myself. I just ran into the command line option of Processing and I saw this info which is relevant to this post. I did ask here before what you would need to generate a class file and the answer was Eclipse or java's own command line. However what I understand is that you need to still open the jar file and move the new generated class file into this jar file, basically overwriting the previous class file. This is what I get from this current discussion. If I ever get to try it, I will post it here if this works.

    Kf

Sign In or Register to comment.