Including shared pde files across projects

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:

This is addressing your MamalsInt case. Open a terminal in an empty folder. Copy the code below and paste it in the command window (In windows use Ctrl+INS key combination). it will run, create the java files, build their respective class files and run the code.

Another thing you can do is to copy this code into a bat file aka run.bat. To edit the file, right click on the file and choose edit instead of open, as the latter will execute the bat file. Then in the terminal window go to the folder containing the bat file, open a cmd window and type “run.bat” and it will execute.

Kf

P.S. Notice I have removed the definition of package above. If you use the package line, when java builds this file via javac, it creates a folder called “animals” and places the .class file there. When you build MammalInt.java using the commands above, it won’t be able to see the Animal.class definition.

File Run.bat

REM Writes java file
REM
echo //package animals; > Animal.java
echo public interface Animal{ >> Animal.java
echo	public void eat(); >> Animal.java
echo	public void travels(); >> Animal.java
echo } >> Animal.java

REM Writes java file
REM
echo public class MammalInt implements Animal{  > MammalInt.java
echo	public void eat(){    System.out.println("Mammal eats");   } >> MammalInt.java
echo	public void travels(){System.out.println("Mammal travels");} >> MammalInt.java
echo	public static void main(String args[]){MammalInt m= new MammalInt(); m.eat();m.travels();} >> MammalInt.java
echo } >> MammalInt.java

REM Builds java files
REM
javac -d . Animal.java
javac -d . MammalInt.java

REM Runs the code
REM
java MammalInt

Output of “java MammalInt”

C:\Users\C\Pictures\Sell-June-2018\armband>java MammalInt
Mammal eats
Mammal travels
3 Likes

for kfrajer

the code did not run without some minor editing, for some reason the spaces or tabs between echo and public on a few lines were ignored making the line echopublic … so replaced the existing space/s with space in a text file added a fully qualified path to the javac line and copied and paste again

copied and paste the text into cmd shell works

ran the batch works

**** SUCCESS ***** !!! woo hoo

the batch file created the two java files and and compiled the two classes

Animal.class
MammalInt.class

then ran >Java MammalInt

it returned

Mammal eats
Mammal travels

That was an excellent example.

Now that I have something that works I hope that I can move that success to the other directories I will then be ecstatic

Thank you very much for your feedback and the batch file

1 Like

for akenaton

5’ and 10’ means 5 seconds and 10 seconds perhaps ? ? ? ? ?

thanks for your post

C:\Users\mnmmc\Documents\Processing\project\animal_pkg\animals

“C:\Program Files\Java\jdk1.8.0_101\bin\jar” cvf animals.jar *
added manifest
adding: Animal.class(in = 138) (out= 119)(deflated 13%)
adding: MammalInt.class(in = 688) (out= 409)(deflated 40%)

the above creates animals.jar

“C:\Program Files\Java\jdk1.8.0_101\bin\java” animals/MammalInt
Error: Could not find or load main class animals.MammalInt

I don’t seem to have any trouble creating class and jar files just getting them to be useable

kfajers provided me a batch file that created an excellent animal and mammalint example with class files that are useable I created a jar from them but the found that the jar was not useable so am still struggling.

When I 1st created the “Command.jar” I remember I used something to automatically place its “.class” compiled file in its correct folder. :crazy_face:

But b/c this time I was more focused on the jar command than javac, I didn’t care to rediscover how I did it. So the trick is the argument -d .! :hushed:

Having javac placing the “.class” files in their correct folder on its own it’s 1 less vector for human errors. :relieved:

Like for example, creating the “.class” folders w/ the wrong capitalization (“Malcolm/” instead of “malcolm/”); thus failing to match the package’s exact name! :cold_sweat:

Again, I’ve re-updated my “Processing_Jar_Creation” repo to use the new -d . argument for the javac command within the “.bat” file: :upside_down_face:

Actually, it’s a unified “.bat” now: “CreateJarFile.bat”javac -d . *.java && jar cf Palette.jar * :smile_cat:

2 Likes

for GoToLoop

Some success woo hoo

earlier today I changed the path on my machine I was having some issues having to add fully qualified paths to the jar javac commands I found that
I had a path to C:\Program Files (x86)\Java\jre1.8.0_31\bin
changed it to C:\Program Files\Java\jdk1.8.0_101\bin\
I am not sure what effects this may have had on anything that has preceeded

anyway back to your post

Copied fresh all of files from the GitHub and loaded up Processing

ran PaletteJarSketch and it worked BUT* Processing STILL SAYS
No library found for malcolm.Palette

so renamed all of the files so that they could not be used and finally ended up with just the
PaletteJarSketch.pde and the
C:\Users\mnmmc\Documents\Processing\libraries\Palette\library\Palette.jar and

ran it and I still got output with Processing saying No library found for malcolm.Palette

renamed the library Palette.j_ar I now get no output and a much more verbose error message

The package “Malcolm” does not exist. You might be missing a library
No library found for malcolm
No library found for malcolm.Palette
Libraries must be installed in a folder named ‘libraries’ inside the sketchbook folder (see the Preferences window).

So I am very happy that PaletteJarSketch is using the library Palette.jar and I now need to make sure that I can replicate this again and again AND understand what the hell I was doing wrong before.

Find it somewhat annoying that Processing is telling me there is no library when clearly it is being accessed - but I guess I don’t care as long as it works.

To all responders

I do appreciate all of the help provided by all responders but I must admit that I was getting a little swamped.

I shall now go back over all of this to determine why gotoloops repository stuff works now and why the earlier stuff didn’t.

Thanks again to all ! ! :grinning:

2 Likes

You may try out your luck reporting it below: :flushed: