Put an icon on the jar file - java

I need to put an icon on the jar and I don't know how I can do this. Reading on google some people suggest me to use some wrapper. My question is this: Can I put an image on the jar without install this wrapper? Anyone can help me?
I mean this image:
http://it.tinypic.com/r/ngksp/8

It's not possible (without wrapper). Java is cross-platform language and icon format itself is often "platform dependent" - operating system is in charge of "linking icons to files business".
Set Icon for executable Jar file
How to change executable jar file icon?
How to set ICON image for java.jar executable jar file

Related

JavaFX, can't get icon on the title bar to show up after exporting to *.JAR

Every time I export my project into *.jar in eclipse I lose all of images in my project (in Eclipse). I've tried to put images directly into the *.jar and it works in some other cases but not this one.
Fragment of code with loading of this icon:
primaryStage.getIcons().add(new Image("file:icon.png"));
You're loading the image from the working directory, not the jar itself. This is why it's working in development, and not in production. If you move the image to the same folder as the jar is located it should work, but I'm assuming you want the image to be contained inside your jar file.
Move the image to one of your packages (any, as long as it gets bundled with the jar). Then you need to access the image, use the ClassLoader.getResourceAsStream(String) for this. It looks like you're using javafx, so you can use this to get your image: primaryStage.getIcons().add(new Image(ClassLoader.getSystemResourceAsStream("the/path/to/your/image.png"));.
to work with the files inside the jar, need to use ZipInputStream or JarInputStream

Converting .jar which uses pictures into .exe

I made a program in Java which uses plenty of pictures(every JButton has one).
I exported .jar file from my project and converted it to .exe using JSmooth. When I run .exe, everything works fine on my computer, but on other computers there are no pictures on the buttons. How should I provide those pictures with .exe, so everyone can use program, not only my computer?
I searched everywhere, but I can't find my answer, please help!
This is the example of loading images:
buttons[index].setIcon(new ImageIcon("cards\\"+(index+1)+".png"));
What is the reason that you want the jar file to an exe file?
If you mark the Java file as an executable, then you should be able to execute the jar on windows.
It is possible to package the pictures in your Jar. The preferred way is to adept the script where your IDE creates the jar. Which IDE (integrated development environment) do you use?
--- edited ---
The following code you need in your java code:
buttons[index].setIcon(new ImageIcon(getClass().getClassLoader().getResource((index+1)+".png")));
After creating the Jar file, you can open it with an archive program (like winzip or something like that), and you copy the images in the jar file (root).
If you want to do this program automatically, you need to generate an ant file. And adapt this ant file, so that it copies also the png on the fly, more info can be found here: https://ant.apache.org/manual/index.html

How to launch draw9patch and is it absolutely necessary to rescale pictures?

I read on another forum that to launch draw9pad from your console, you have to do java -jar draw9patch.jar from the command prompt once youre in sdk. I did that but i still cannot launch the file. Is this tool absolutely necessary for your pictures to scale on different screens? I know that eclipse has these drawable folders that scale your pictures to different dpis or is that not what they do?
Console output: http://imgur.com/YdGLHXr
File skd/tools :http://imgur.com/vOU647L
To answer the first question for a Mac OS or Linux user, simply type sh draw9patch to launch the editor. CommonsWare already answered the second question.
I read on another forum that to launch draw9pad from your console, you have to do java -jar draw9patch.jar from the command prompt once youre in sdk
Please use the draw9patch batch file or shell script found in the tools/ directory of your SDK installation.
I did that but i still cannot launch the file
First, that is because you did not type it in correctly, as you did not include the .jar extension.
Second, that JAR file is not in that directory. You can tell that by looking at the directory contents.
Instructions for running draw9patch can be found in the Android documentation.
Is this tool absolutely necessary for your pictures to scale on different screens?
Quoting the documentation:
A NinePatchDrawable graphic is a stretchable bitmap image, which Android will automatically resize to accommodate the contents of the View in which you have placed it as the background.
Scaling for different screens is not really the role of a nine-patch PNG file. Scaling for different content is. A nine-patch is used as the background for widgets like Button, EditText, and the like.

Exporting processing to a jar file

I've been working on a processing application using ControlP5 and Twitter4j. I want to have my project run from a single jar file from any operating system. Basically I want to package up my application. My application uses images. I've been browsing for more than an hour, but I cant find how to do this. Any suggestions?
using
processing 2
twitter4j3
Thanks in advance!
I dont know if you can directly do it from the Processing IDE however, if export your sketch to a Java applet then locate the .java the the sketch folder you can use this in conjunction with Eclipse to export to a jar file.
So, I know that this post is very old but if you are still looking for a solution, or to other people that see this thread, it's relatively simple.
Export the project
In the folder with the exported project (something like application.windows64), navigate to lib and find core.jar and project name.jar (you need to have file name extensions visible)
Rename the files to .zip files
Extract core.jar to whatever folder
Extract project name.jar into the same folder (make sure you don't do it into a subfolder)
Click yes if it asks if it wants you to replace a file (if it doesn't you extracted the files incorrectly)
Delete core.jar and project name.jar
If the project uses images, move them into the same folder as all the other files
Select all of the files in the folder, right click, hover over send to and select compressed (zipped) folder
Rename the .zip file to name of project.jar
This might be old, but i still find other posts about it on processing forums.
This is the best way to run processing project as a jar file.
When exporting application, you will always end up with a lib folder inside exported application(whether for Linux and Windows). For windows, open command prompt(or power shell), you can use right-click+shift and then click on open power shell here.
After that you can run the following command.
java -classpath lib\* DisplayDepthStream
Now DisplayDepthStream is the name of sketch file.
To explain the command, -classpath lib\* tells java to add everything under lib directory to the class path. And DisplayDepthStream is the name of my main class.
Hope this helps~!
Chears

How to use Java JSmooth to include images in executable file?

Im creating a runnable Jar file from Eclipse for a Java file. The Java file has a combobox that changes the image depending on the selection.
Im creating an .exe file for windows using jSmooth.
The .exe runs fine and the images change as expected when the images are in the same file as the .exe file.
How can I "include" the images in the .exe file such that I could send the .exe file to someone without sending them a bunch of images too (using jSmooth).
I do not see a clear method for doing this in JSmooth
What I found out. Using netbeans you can create a label and select an icon in the properties section and this will include the image for you in the jar file.

Categories