Including shared pde files across projects

Ok so there are some interesting things. if you load your jar file inside your sketch aka inside the code folder, then you do not need to state the import statement. You will be able to use it at your leisure. Notice, as dealing with any interface, one needs to use Pallete.RED as RED will not work.

Now, if you move this library to the Processing’s libraries folder like this:

yourSketchFolder/Libraries/malcolm/Library/malcolm.jar

Notice: I am in Win10 OS. Folder names is case sensitive in other OSes.

Then you need to include at the top of your sketch import malcolm.*; OR import malcolm.Pallete;, the last one is preferred. Notice you don’t need the static modifier for the import.

Notice this layout: yurSketchFolder/malcolm/Pallete.java and the first line in your java: package malcolm;

Another scenario:
Notice this layout: yurSketchFolder/malcolm/Pallete/Pallete.java and the first line in your java should be: package malcolm.Pallete;

When you create the jar via “jar cf malcolm.jar malcolm”, the last term indicates the folder to attach to the jar. This will also attach any other subfolders and their contents. So this jar cmd would work for either scenarios above. Notice the last term is the folder name and it does not have any slash attach to it (backlash for Windows users).

Kf

1 Like

Due to many conflicting instructions so far, I’ve felt I needed to create a repo just to demo more clearly my own step-by-step howto that I’ve already posted here in this forum thread: :cowboy_hat_face:

There are 2 main folders in that repo: :face_with_monocle:

  1. “PaletteJarCreationFolder/”: where the whole processing of creating the “.jar” file takes place.
  2. “PaletteJarSketch/”: The “.pde” test sketch which uses the “.jar” file created at “PaletteJarCreationFolder/” placed in its subfolder “code/”.

Within “PaletteJarCreationFolder/” we can spot the 2 “.bat” files “Part1.CreateClassFile.bat” & “Part2.CreateJarFile.bat” which contain the command lines I type in to create “Palette.class” & “Palette.jar” respectively: :male_detective:

  1. “Part1.CreateClassFile.bat”: javac *.java
  2. “Part2.CreateJarFile.bat”: jar cf Palette.jar *

Hope it’s now very clear on how I did it and you can mime it if you wish. :innocent:

1 Like

Again thank you both for your time.

I spent some quite a bit of time trying to make this work trying this that without much success. Most recently I saw GoToLoop had provide some new files , thank you for that.

kfajer indictes a number of different places and options for the library
tried putting the jar in libraries/Malcolm/library (libraries)
tried putting the jar in Processing/libraries
tried putting the jar in Processing/libraries/Palette/library
tried putting the jar in the project/Palette.JarSketch

I can create the java file with the files provided by GoToLoop run the batch files and create the class and jar files but cannot get the program to link (is that the correct term???) to the jar.

If the Palette.java file is placed in the same directory as the pde the program runs and creates output.

This is all getting very wordy and I was finding it very confusing so I have created a pdf of where we are at if you would kindly have a look, the diagram attempts to show that the PaletteJarSketch.pde runs and produces output when Palette.java is in the same directory but when Palette.java is not available Processing is unable to find the jar file.

15 Jul modified jpg

1 Like

It seemed to me that the jar file should be named malcolm as the pde imports malcolm.Palette, had this vague idea that the jar should have the same name as the package
so I changed the second bat to create malcolm.jar , that worked ok , well it didn’t complain, stuck it in libraries/malcolm/library and restarted Processing, crossed my fingers and groaned, didn’t work ! ! This is so painful!!

For your library folder, then do in a cmd window tree /a /f and post here. Also, post the package line that you are using and the jar command to pack your library. This is what I did in my prev post. I am asking only for the library. Do not include anything relate to your pde that you are using to import this lib of yours.

Kf

Not according to the article for installing libraries in Processing: :no_entry:

The top folder of a library must have the same name as the .jar file located inside a library’s library folder (minus the .jar extension):

Therefore, we’re free to choose whatever name to the “.jar” file, as long as we use that same name for its top folder. :face_with_monocle:

My “.jar” file was named as: “Palette.jar”. So in order to integrate it to the PDE, I’ve gotta name its top folder inside sketchbook’s “libraries/” folder as “Palette/”: :file_folder:

 +---libraries
|   \---Palette
|       \---library
|               Palette.jar

However, after I’ve completed the “.jar” integration into the PDE, when running the “PaletteJarSketch.pde” w/o the “Palette.jar” inside its subfolder “code/”, the statement import static malcolm.Palette.*; didn’t work! :face_with_head_bandage:

I had to use a regular import before being able to use the import static: :crazy_face:

import malcolm.Palette;
import static malcolm.Palette.*;

I’ve updated my “Processing_Jar_Creation” repo to include this extra import statement already. :smile_cat:

And even included the PDE’s “.jar” integration there too: :sunglasses:

1 Like

for jfrajer

'C:\Users\mnmmc\Documents\Processing\libraries>tree /a /f
Folder PATH listing for volume OS
Volume serial number is 3E47-3D32
C:.
| malcolm.jar
|
—Palette
—library
Palette.jar

tried adding both

import malcolm.Palette.;
import static malcolm.Palette.
;

as GoToLoop suggested but get

No library found for malcolm.Palette
No library found for malcolm.Palette

neither one nor the other nor both work

checked my Preferences again C:\Users\mnmmc\Documents\Processing so it seems to me the libraries are in the correct spot and named correctly

.

for GoToLoop

changed my PaletteJarSketch.pde to include both import lines and copied the Palette.jar from repo to libraries/Palette/library run the sketch

No library found for malcolm.Palette
No library found for malcolm.Palette

so if this works for you is it some necessary environment setting that is not set on my PC

I have java/jre1.8.0_31
Processing is 3.3.7
Sketchbook location C:\Users\mnmmc\Documents\Processing
libraries are in that directory
I am wearing my lucky shirt and have a 4 leaf clover on my desk

If C:\Users\mnmmc\Documents\Processing\ is the actual folder where all of your sketch folders are, the “Palette.jar” file should go into this path of folders: :male_detective:

C:\Users\mnmmc\Documents\Processing\libraries\Palette\library\

Make sure PDE isn’t running when you manually change anything inside your C:\Users\mnmmc\Documents\Processing\ sketchbook path. :ok_man:

C:\Users\mnmmc\Documents\Processing>tree +some files
C:.
├───libraries
│ └───Palette
│ └───library
-------------------- Palette.jar
├───project
│ ├───PaletteJarCreationFolder
│ │ └───Malcolm
--------------------Palette.java
│ ├───PaletteJarSketch
---------------- PaletteJarSketch.pde

closed processing restarted

same result No library found for malcolm.Palette

thanks again to both of you,
I am going out for a number of hours so I haven’t given up and will not be ignoring you just away.

“Sketchbook/”:

+---libraries
|   \---Palette
|       \---library
|               Palette.jar
|
\---PaletteJarSketch
        PaletteJarSketch.pde
  1. "Sketchbook"/libraries/Palette/library/Palette.jar
  2. "Sketchbook"/PaletteJarSketch/PaletteJarSketch.pde

Yep. That’s what I have got ! ! !

So it didn’t work yet?! :space_invader: According to your tree: :thinking:

Appears to me the subfolder “library/” isn’t inside subfolder “Palette/”? :roll_eyes:

You missed this info in your post for me.
Also, open a cmd terminal, go to the folder that contain your jar file and type pwd. Paste here what you get.

Kf

oops sorry

the package line is

package Malcolm;

I am using windows10 so pwd does not work but all of the files are in the sketchbook location
C:\Users\mnmmc\Documents\Processing

the jar file is created in
C:\Users\mnmmc\Documents\Processing\project\PaletteJarCreationFolder>
using the batch files provide by gotoloop which implement
javac *.java
jar cf Palette.jar *

@malcom_gc===
5’ to do that with Eclipse:

create new java project
call it as you want
inside it create a package, in this case i have named it “palette”
inside this package create an interface, in this case i have called it palette also
in this interface copy @GoToLoop code (Yellow and so on)
now go to export
choose export as jar
save it where you want, it will be saved as “Palette.jar”
in processing libraries create a new folder Palette
inside it create library folder and put your jar inside it
then run the code::


import palette.palette;
void setup(){
//does not claim about library
  background(0);
  fill(palette.YELLOW);///Yellow is defined inside the palette class
  ellipse(50,50,20,20);
  
}

O course if you dont have Eclipse you can use the jdk tools

  • firstly javac
  • secondly jar

PS: i dont know why but i cannot post images about the contents (from Pacifist) and the folders structure…

1 Like

You can choose any name for the package statement, as long as you put the generated “.class” file inside folders w/ the exact corresponding name of that package when creating the “.jar” file! :pensive:

akenaton

sorry I am not sure what the first two lines of your post indicate

@malcom_gc=== < maybe just to get my attention ??
5’ to do that with Eclipse: < I read 5’ five feet and isn’t Eclipse a different java package ? ? ?

I do appreciate your feedback.

I think your saying I should export this package into a jar file using Eclipse. Whilst I appreciate that some IDE might be able to do this, I would really like to understand why we haven’t been able to do it using the command lines of javac and jar

Because of the issues I have had in the posts above I have also been playing with the example for Animal and MammalInt in the following

http://www.tutorialspoint.com/java/java_packages.htm
describes how to compile to a class

https ://sites.google.com/site/alljavadevelopers/j2se-turorial/package (remove the space to make the link)work
describes how to run the class
mind you not sure whether your supposed to make a jar with this as neither link describes making a jar so did it anyway

and am finding that I can create the class and jar files but I can’t run them, the second link describes the commands to run the class (or maybe jar)

This seems to me to point to some environment issue that my system has. Adding another package (Eclipse) may just exacerbate my issues.

As I said in the previous post I have been trying an example described in http://www.tutorialspoint.com/java/java_packages.htm and https ://sites.google.com/site/alljavadevelopers/j2se-turorial/package (remove the space to create a link)

and, am having a similar problem so I do think that it might be some environment issue

the jpg below shows the files and commands and failures

1 Like

@malcolm_gc===

i have spoken about Eclipse because exporting to .jar is included and so it is possible to get your .jar in 5’ (including the cut && copy from @GoToLoop.
Now i have taken your animals example and made the same thing with command line
from your image i see that you have successfully created your classes with javac; so the error is with your command for creating the .jar: supposing that you cd to “animals” where are your classes then in the terminal you write:
jar cvf animals.jar *
with the c you obtain the jar as it is named which says the f
with the v you get the verbose issue
and normally after that you get a .jar
i have got it…:10’ :yum: