I need to send a project made by JavaFX SDK 16 and Java SE-15 using Eclipse to my friends, but when I try to export it, i'm getting surprised that Eclipse doesn't insert the VM arguments to the exported file :
and as you know since JavaFX SDK 10, JavaFX libraries are not anymore part of the Java SE, so we need to tell Eclipse where to find them by VM arguments, in short words, these VM arguments are really important to run my program.
I already know that I can insert those arguments while using prompt command to open it, but is there a more simple way? just by clicking on the exported file ?
Your main problem is that you are trying to do something that does not make any sense. Runnable jars are not a proper distribution format for JavaFX applications for various technical reasons. The way to go is having a look at jpackage. That's the proper way of dealing with distribution nowadays. Otherwise your are just banging your head against a wall.
Here is a good summary of all the options you have: https://stackoverflow.com/a/68823040/4262407
I have this problem 5 years ago (I use netbeans IDE, so I don't know if it works in eclipse, but I think yes), and I cant find a good way to do this.
Instead, I created one Swing application, and put all code of JavaFX inside.
You could see how I do in
this link from Oracle.
Related
Two days ago I got close to finishing a java program that wrote, I wanted to let some friends play with it for a bit to find flaws etc. I created a runnable jar trough Eclipse and then I used Launch4j to transform the runnable jar into a .exe
It worked perfectly fine on my pc, but any other user couldn't open it. After a while I discovered that when people would install java JDK, it worked for about 40%, but this atleast pushed me in the direction of what the flaw is. Is there a way to (automaticly?) embed everything in the jar that my program is in need of? Or is there a way to determine what exactly it all is that people need for the .exe to run and what they are missing by running some pre-checks that can re-direct them to links where they can download this? I can't seem to find much on this subject, so I probably made a mis assumption somewhere, any help/clearance is appreciated!
There is a new tool called jpackage, which should do what you want.
Also see the User's Guide.
I wrote a simple java code that would take simple inputs from the user in the command window (of eclipse for me) using nextInt() and nextLine(). However, I realized that others need JRE (I believe?) on their computer to run the executable jar file made. So I was wondering if there is a way to get around that by making the app produce a window that is like the command window to have the same interaction as the command window in eclipse.
So, if I were to run the .jar or .exe then a simple window would pop up that acts like the console of eclipse displaying lines from System.out.println() and etc.
To run a java program you need the jre. There is no way around that.
If you need the console, nothing is stopping you from running the java program from the windows command line, which will do exactly what you ask for.
You still need the JRE.
Unfortunately, when starting to learn Java with Eclipse, many people miss the opportunity to at least start to understand how to do the same from the command line, which is, if you ask me, good to know.
For programs written in Java, they are compiled as a jar file, like you mentioned, and how these compiled versions of your source code differs from many other programming languages is that they do not contain the assembly/machine code like for example a compiled C program would have. They are instead compiled as bytecode. Which is special code for execution by a Java Virtual Machine. Here is a good Wikipedia reference: link
To answer your question, yes, others need a JRE (Java Runtime Environment) and this can be either:
Installed by themselves (this is what you mentioned)
Packaged together with your java app, to provide a download-and-click experience.
For option 1, assuming they already have it installed, they can simply run it by executing the jar file with javaw, more information on that is in this previously answered SO question
For option 2, the process is fairly lengthy and I'll point you to the official docs to refer to: self contained executables and Deploying java apps
If you have a more complex project with third party libraries and what not, look at this SO question
In the past, I've also found launch4j, a cross-platform wrapper to be very useful, it automates the process of going from jar to an executable (made a simple game that using Swing, simple and ugly thing it was), but the user still needs a JRE, nonetheless. :)
Hope this helps!
I'm reading pdf files with python. And in my script, i'm calling a jar file by command line using os.system.
Two things here:
OSX annoyingly keeps redirecting me to desktop everytime the jar is called. I can optmize that, but I don't want OSX to do that; and
Isn't there a way to no actually open java internally ? Like attaching the code inside my python script. Let's just say I don't want the user to see java being opened.
Thanks in advance.
You may want take a look at similar discussion here. To summarize the discussion, you can use Py4J.
There is also another project called JPype, however that seems to be a very old implementation (way back in 2009) and no updates thence.
I made a simple command-line based game in java, only two classes (using Eclipse). But I was wondering how I can make this into a usable application for anyone, without running it through eclipse (ie send it to someone who knows nothing about java but would still be able to play the game)? Thanks!
You want to create a runnable jar file.
Eclipse has an option for this in the "Export" menu. For more options, search for "executable jar file" here or on Google.
You want to make sure that you also include any jar files your code depends on as well (Eclipse can also do that for you).
Users will be able to start this by double-clicking on the file on most platforms. If you need better integration (such as a custom icon), you will need to bundle it up further into an OS-specific executable. But for starters, a simple runnable jar works fine.
send it to someone who knows nothing about java
You need to get them to at least install the Java runtime on their machine (if it is not already there).
Just to be clear, "command-line" and "knows nothing about java" are probably not going to work very well for you given that:
java is OS agnostic, therefore, if you send (presumably) a jar file to say...your grandma and she has a mac and you have a PC chances are her getting it to work is not going to be "out of the box easy" so to speak.
Left with this, I think you have a couple choices...first off, you do need to package your classes - a runnable jar will work fine. Aside from that, you will most likely have to build OS specific scripts (batch scripts for Windows, shell scripts for unix, etc.) and you will have to hand these out with your jar file. That being said, the intended user will still need to have java installed, and the batch scripts themselves are not likely to be trivial endeavors.
Your next option would be to use JNLP. However, I don't think JNLP has a command line mode, so you will likely have to simulate a console with something like a JTextArea.
As far as I see it, your last option it to use one of the many products (not sure if there are any free ones) that package java into native code. I think Exe4j is one such example - but, like I said, I am not sure if there are any free ones and I am not sure how hard they are to use.
Best of luck, and if you can't get your jar to work you should probably move that to its own question.
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
How can I convert my java program to an .exe file ?
I've used JSmoothGen in the past, but recently we've seen a number of machines that refuse to run the .exes that it generates. It also seems not to be actively maintained so heavily any more.
Are there any alternatives that are more actively maintained and more reliable?
I use Launch4J which supports Windows, Mac and Linux. I suggest forgoing the somewhat flaky GUI tool and just writing the (short, readable) config file yourself.
The gnu compiler
gcj
I found this article to be very informative http://www.excelsior-usa.com/articles/java-to-exe.html.
Someone already mentioned Launch4j, however, I found Jsmooth to be alittle better. They are both very similar, but I would mess with both to see which you prefer.
EDIT: Sorry, I somehow skimmed over your mention of Jsmooth in your question. If Jsmooth isn't working for you, then I would go for Launch4j. I still recommend that article.
http://sourceforge.net/projects/javaround
HTH
It is also not entirely necessary to make an .exe. On Windows, at least, .jar files are executable so long as there is a Java runtime installed and the .jar extension has been set up on the machine.
[NOTE: I just discovered that something that has broken the file association, which had previously worked for me. It now only works when I am administrator, and the JAR icon even disappears otherwise. I assume that some recent install has messed with that and the candidates are (1) OpenOffice.org 3.0, (2) WinRAR, or (3) a Java update download. However, the following all work when the association is made to work.]
The "program" Clicker.jar runs as a Java application when (1) I double-click on it in a Windows Explorer window, (2) When I create a console shell where I am in the same directory and I perform the command ">Clicker.jar" (3) when I send a shortcut to my desktop and double-click on it, and (4) when I put the full path in the Windows XP Run ... box.
I don't know that these will be found in a PATH search, and I normally wouldn't arrange that anyhow.