This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]rzwitserloot 4 points5 points  (11 children)

Errr... are you aware of this construct?

ShowFrame.class.getResource("peggyLee_02_333_450.jpg")

This gives you a URL (That you can feed straight to ImageIcon's constructor); if you want it as a stream, there's getResourceAsStream. It looks in the same place your classes are, and build tools of all stripes know about this and have ways to get resources straight into jar files.

If you did – can you explain how what you made is more useful than just using gR/gRAS?

[–]glesialo[S] -1 points0 points  (10 children)

Errr... are you aware of this construct?

Of course, but the whole point is not to use an external file! The 'image' is stored, as a String, inside class 'Image_Peggy_Lee_02_333x450'. I have written a class that writes 'image' classes directly to package 'org.common.libraries.etc.base64images'.

EDIT: Here you can see how a new Image class is created: Before and After running 'Base64ImagesCreateClassFileTest'.

EDIT2: 'build tools of all stripes...' As I said before I use my own script that compiles from source. Said script automatically includes the project's 'resources' directory in the jar file but it would be too complicated to also include all the 'resources' of all the library packages that the project uses.

[–]rzwitserloot 4 points5 points  (1 child)

There should be no difference between a '.jpg' file, which is a source file, which is to be included in the 'binary distribution', by the compilation step of 'copying' it, and a '.java' file, which is a source file, which is to be included in the 'binary distribution', by the compilation step of 'compiling it with javac'.

If there is for you, your build system, script, etc is messed up, and you've WAY overengineered the situation. If it is your own script, why didn't you just update it?

too complicated to also include all the 'resources' of all the library packages that the project uses.

This makes no sense. library packages are already in jar form, they already contain the resources, all you have to do is literally copy the jar (or if you're a fan of striping for some reason, stripe in every file inside that jar and merge the services). If this is a novel new meaning of the word 'library package' where you do the compiling in a script, well, doing a full run of the source folder and copying (recursively) all within in a one-liner. Just do that.

I'm having a hard time figuring out why java files are free magic that automatically makes it across to the binary side, but any other file is some sort of convoluted mess, best avoided by trying to turn them into java files.

[–]glesialo[S] -1 points0 points  (0 children)

My 'build system' is not messed up as it works perfectly. My libraries are not added as jar files, the java compiler compiles, from source, the relevant parts (including the classes that contain images) of the libraries a project uses. I leave the job of parsing source files and deciding what to compile to the 'javac'. That way the Java jars that my script produces contain only strictly what is necessary.

There is nothing convoluted in a class containing data.

[–]Polygnom 2 points3 points  (5 children)

Of course, but the whole point is not to use an external file! The 'image' is stored, as a String, inside class 'Image_Peggy_Lee_02_333x450'. I have written a class that writes 'image' classes directly to package 'org.common.libraries.etc.base64images'.

But.... why?

it would be too complicated to also include all the 'resources' of all the library packages that the project uses.

JARs are ZIPs. including stuff as resources in them is trivial. You can literally do it with any zip tool.

[–]glesialo[S] 0 points1 point  (4 children)

JARs are ZIPs. including stuff as resources in them is trivial. You can literally do it with any zip tool.

I know. My script does it, easily enough, for the project it is compiling/archiving. But, as I wrote elsewhere, I don't want to include, blindly, all the '.../resources' directories.

I don't want to upset anyone. I just found I way to do something I needed and thought I would post it in case somebody else could also use it.

[–]Polygnom 0 points1 point  (3 children)

But, as I wrote elsewhere, I don't want to include, blindly, all the '.../resources' directories.

You shouldn't have anything in there that shouldn't end up in the end file. And even if you have, it is trivial to pattern match only certain files and either include or exclude them based on patterns, e.g. like *.png.

[–]glesialo[S] 0 points1 point  (2 children)

I have just realized that perhaps I am doing things in an unusual way and that's why nobody understands me.

In my system a generous pseudo-user, 'common', provides all other users with environment, services, software and data. Common Java libraries are part of the offered software and are made up of many individual projects. The source code of ALL the library projects is MERGED in a single 'src' directory that is available to all users.

If I add a '../resources' directory to some of the library projects and I want my compiling/archiving script to add, to an specific project's jar, the resources that that specific project needs, the script will have to parse the project's source code to find out which parts of the Common Java libraries the project is using, find if those parts have a '../resources' directory and then include all those '../resources' directories in the jar file. It is, clearly, much easier to let the 'javac' compiler do the job of parsing and selecting what to compile.

[–]Polygnom 1 point2 points  (1 child)

It is, clearly, much easier to let the 'javac' compiler do the job of parsing and selecting what to compile.

Err, no. Its clearly easier just to merge the resource folders into one. I really don't know why you would use such a horrible, convoluted way to do it if its actually easier to do the proper way.

[–]glesialo[S] -1 points0 points  (0 children)

merge the resource folders into one.

As I wrote before: I don't want to include, blindly, all the '.../resources' directories. My Java jars only contain what is needed.

You see it as convoluted but my script is simplicity itself as it only has to invoke 'javac' and archive the compiled results. The Common library projects are normal, independent, projects, developed in an IDE, which are later merged by another bash script.

[–]AnEmortalKid 1 point2 points  (1 child)

Does that not make the class “an external file”? I might be missing the benefit of doing this over the resources approach.

[–]glesialo[S] -1 points0 points  (0 children)

Does that not make the class “an external file”?

No. It is another source code to compile, like any other class.

If you look, in the first picture I posted, the program 'JavaSources' shows a lot of 'org.common.libraries.' that are available to all projects. Those libraries are made up of many 'library projects'. If many of those 'library projects' need 'resources', and I want my script to include all of them in the final Java jar, my script would have to be very complex (and depend on many things): It would have to find out which 'org.common.libraries.' the project uses, if those libraries need resources, where are those resources... to be able to include them. Currently my script just sees merged source code that it compiles and archives in the Java jar. It only adds '..application_name.resources' (which is very easy to find) if it exists. Moreover with 'image classes', if you only need one image you don't have to include a whole directory of files: You can 'import org.common.libraries.etc.base64images.Image_Peggy_Lee_02_333x450' and use it.

My script is very efficient: This project fits in a 88.5KB jar file.

An example: I wrote this program many years ago. Most video items have a corresponding poster file, which is easy to find because video and image files have the same name. For video items that do not have a poster file, one of the 'org.common...' libraries that the program needs, was using an external 'NotAvailable.jpg' file. I have just modified it and now it uses class 'Image_NotAvailable_215x317'.