I am writing a program which I would like to deploy as both desktop and android applications. I want to use JavaFX 2.0 with FXML for the desktop side of things. I want to work entirely in Android Studio. Right now, I am just concerned about producing an desktop executable (for Windows to start with) for my JavaFX program. I'd like to produce an .exe file if possible, or at least a .jar.
To clarify, I am not asking how to go about deploying/compiling an existing JavaFX project for Android. I know there exists something called JavaFXPorts for that. I just want to compile and deploy a regular JavaFX program using Android Studio, totally ignoring anything to do with Android for now. (If JavaFXPorts somehow helps with this, then by all means, please show me how).
So far, I've managed to create a regular Java application in Android studio, add in some 'hello world' JavaFX files, and (sort of) deploy the program.
There are many questions squeezed into this one SO question.
I don't know where to put my FXML files so that my final Jar file can find them. I think I have to get gradle to copy them to the build directory, but I don't know what the standard way of doing this is. Do I need to put my FXML files in a 'resources' or 'assets' directory? How do I write a gradle script to copy the files over? Should I refer to the FXML files directly, or through the resources system?
It seems that IntelliJ does this automatically using compiler resource settings, but Android Studio is missing this functionality (probably because it assumes I only want to create an Android app, so only need to use the Android resource system).
Just as a reminder, the entire relevant part of my project is located in a 'Java Library' module in the Android Studio project.
I've created an test project which I've uploaded here: https://github.com/Aralox/Android-Studio-FXML-Executable-JavaFX-Project
Here are a few screenshots:
Complaints about a missing 'resources/main' directory. This probably has something to do with the JavaFX gradle script I copied from here. I manually added in this directory for the program to compile (super hacky).
My program couldn't find the FXML file it was looking for because of a change in working directory (hacky way of finding the FXML because using getClass().getResource() did not work, because the FXML was not copied to the output directory).
Final program working after I manually copied the FXML file into the build directory (and told the program where to find it).
I know this was a long question, but I hope I've made my essential problem clear. The 'child' questions are just problems I encountered in my attempt to find a solution. Thank you very much for the help!
Related
I used to work on an IntelliJ project that was started before I started working on it. This project had a configuration that allowed me to generate an EXE file that could easily be sent to windows users.
It would generate a massive EXE file bundled with all the needed JARs of the application, and upon running it the first time, it would silently "install" itself into the AppData folder, as if it were a regular windows setup file, even though the user would not even notice it doing that installation.
I am trying to configure a project in IntelliJ to do the exact same thing, but first I have not been able to output the exe file by selecting "exe" as the Java FX native bundle type. It just generates a .jnlp and .jar file. When I select "all", as per some other post here in stackoverflow, it generates an exe file, but only with a few kb in size, which does not contain any of the .jar files that should be part of it. Moreover, when I try to open it, it just crashes saying the main class was not found.
Am I missing some setting for building the project? I am using IntelliJ 2018.3.2
Here are some screenshots:
I have been able to get past this error, after changing the verbosity of the compilation and going through the logs.
There was a log message which helped fixing this:
The process complained about the Inno Setup Compiler missing, which was right. Makes me wonder why IntelliJ would have that feature built in if it depends on external tools but does not notify the user clearly of this.
Detected [iscc.exe] version 0.0 but version 5.0 is required.
After going to the Inno Setup site, downloading and installing the tool, I was able to get the executable to be generated.
Now I am struggling with another error, which is the executable complaining about the main class referenced in the Artifact not being found, but at least I have moved past the first problem! Going to tackle this one now...
The best solution for this is using exe generator software.
There is plenty of exe generators out there.
EXE4J is the most simple & easy tool to use.
In EXE4J,
You can upload your main jar file and select the main class.
I think this will be solved your problem.
This may be due to you`ve extracted Jars to your output root, while you neet to Put it(you can check difference by deleting everything from your output root in Output Layout screen and then just right click on jar on the right side, you will see two options here, try another one
I have an Android POS device that's equipped with a fingerprint scanner. They have a .jar library which is meant to help develop Android apps to access the fingerprint component in the device. I included the jar file in the lib folder of the NetBeans codenameone project and also in the native/android directory.
But when I run the application on the device after building on the build server, the application throws a NoClassDefFoundError. But the class is in the jar file.
You may need to treat it like a native interface, which is actually pretty easy. You just create an interface with all of the method signatures you need, right click on it, and select generate native. Then in the native sub folder there will be an Android directory. You can drop the jar file in there and in the stub file that ends with "impl", you implement the interface methods to call the methods in the jar.
The downside of that is that the auto-code completion won't work. Since you're using Netbeans, if you do the above you should then be able to compile it into a CN1LIB. That can be then placed in your libraries and the code completion will work.
Check the developers guide in the Advanced Topics Under The Hood section, and there's a tutorial video also.
I've created a game project in NetBeans 6.9, and I want to run the project on another computer. The problem is if NetBeans is not installed on the other computer then surely I cannot run the project.
Therefore I have to convert my project into a .exe that can be run on other computers without having to install NetBeans.
Is there a free application that can convert .java to .exe?
Please help me to convert my project into a .exe file. Thanks.
Check out these official netbeans article for Packaging and Deploying Desktop Java Applications and Developing General Java Applications.
From the article
Running the Application Inside of the IDE
When developing applications in the IDE, typically you will need to test and refine them before distributing them. You can easily test an application that you are working on by running the application from the IDE.
To run the AnotherGrep project in the IDE, right-clicking the project's node (AnotherGrep) in the Projects window and choose Run Project.
The xGrep window should open. You can click the Browse button to choose a file in which to search for a text pattern. In the Search Pattern field, type text or a regular expression pattern that you would like to match, and click Search. The results of each match will appear in the xGrep window's Output area.
Information on regular expressions that you can use in this application are available here and in many other places on the World Wide Web.
Running the Application Outside of the IDE
Once you have finished developing the application and before you distribute it, you will probably want to make sure that the application also works outside of the IDE.
You can run the application outside of the IDE by following these steps:
In your system's file manager (for example, in the My Computer window on Windows XP systems), navigate to PROJECT_HOME/dist and double-click the AnotherGrep.jar file.
You will know that the application has started successfully when the xGrep window opens.
If the xGrep window does not open, your system probably does not have a file association between JAR files and the Java Runtime Environment. See Troubleshooting JAR File Associations.
Distributing the Application to Other Users
Now that you have verified that the application works outside of the IDE, you are ready to distribute it.
You can distribute the application by following these steps:
1: Create a zip file that contains the application JAR file (AnotherGrep.jar) and the accompanying lib folder that contains swing-layout-1.0.jar.
2: Send the file to the people who will use the application. Instruct them to unpack the zip file, making sure that the AnotherGrep.jar file and the lib folder are in the same folder.
The users of your application should be able to run it by double-clicking the JAR file. If this does not work for them, show them the information in the Troubleshooting JAR File Associations section.
Also some third party tools like Launch4j may do the trick. For more information see this article on java-to-exe
See Launch4j. I dislike starting java apps with a batch file. This wraps anything from the root jar all the way up to a complete Java environment in an exe. You get your own icon in the system tray rather than the generic coffee cup. I've used it successfully on a project that has about 300,000 downloads, and it's never been the source of a reported bug. NB It does take some careful reading to pick the right options for your project. But you can set it up with the Ant build script in Netbeans to make the .exe automatically. Very nice and clean. My project includes native libraries. They work fine as well.
I think the NSIS will help you . Most of the applications using NSIS. Because it is open source.
Also there is a Eclipse plugin for NSIS to make the process easy.
http://hmne.sourceforge.net/
I'm trying to import an API that I found online - joda time - into my program.
I've downloaded the files, stuck them in my source folder, but obviously since it isn't integrated into my program they won't work.
I've spent a lot of time googling around for different methods (maybe I'm searching for the wrong thing?) as well as just randomly doing a bunch of different things inside eclipse (I'm developing with eclipse) that include the word "package" or "import", to no avail.
I don't know if it's worth mentioning but my program is being built with the google app engine, and all their stuff is organized in a nice com.xxx.xxxx format, which I think is ultimately what I need to get my stuff into - I just don't know how.
Anyway, sorry if this is a ridiculously trivial question, and thanks in advance to anyone that helps.
You should just have to put the joda-time jar file inside the WEB-INF/lib folder of your project. This folder contains all the libraries that must be delivered with your application, and are automatically added to the build path of your project by Eclipse.
Since you are using Eclipse, you can use the library functions to add in external packages.
Right click on your project, and then choose Build Path --> Configure Build Path.
Click on the Libraries button at the top, and then click the Add External JARs... button.
Select the JAR file in your JODA directory.
If you are using the Eclipse deployment tools, this will automatically package your JAR file in to your web application. If it doesn't do that automatically, add that same JAR file in to your WEB-INF/lib directory (copy it in to your project).
I feel like a 4-year old who has a slice of bread with pb and a slice with jelly and is asking how to make a sandwich..
I've been given the responsibility of maintaining a javaEE website that was done by our parent company that no loner supports us. I'm relatively new to JavaEE and I'm trying to figure out how to recompile the files that need to be modified from within the root folder of the site.
I downloaded NetBeans to help me with this, but still can't figure it out. My problem is that the java files can't find any of the packages and resources they are dependent on. As far as I know, the resources are there.. although, I do see some packages starting with "com." and "javax.", and I don't see a 'com' or 'javax' folder anywhere.. I believe my problem has something to do with setting the class path in the project properties in NetBeans.. I tried that but either I'm not doing it right, or its not working. This whole Java compilation is so foreign to me, it'd be really great if someone could lead me in the right direction of getting this website compiled.
I posted a pick of the folder hierarchy of the website to help:
I'm trying to compile the RecordAdd.java file here specifically at the moment. Some of the packages it is trying to import come from its parent folder, asp, of the folder it is in, easp. The file is also trying to import com.icesoft.faces.component.*; where '*' consists of several different imports of the parent packages. I don't see a com folder like I mentioned, but I do see icefaces.jar files in the lib folder in WEB-INF folder. I've tried putting these folders in NetBeans Library-Compile category classpath, but that didn't do anything.
I'm not doing something right, that is probably a basic knowledge of compiling java projects, but I'm just not getting it. I really appreciate any help, just please don't be too harsh. Thanks!
Try to find out which IDE the original devs used. I see a nbproject folder which indicated Netbeans (unless that was created by you) so try opening the project in Netbeans as a Java EE project. I'd also try to open it in Eclipse, it has good importing capabilities and can sometimes figure out the classpath on it's own. Download the Java EE version of Eclipse and install the Web Tools Project. You can also try to see if there is a build file that will compile and generate a war file for you (something like build.xml).
It should be simple if the project was created in netbeans. Just go to File -> Open Project. Navigate to where the project is located. You will know if the folder is a project, because netbeans recognizes it and a different icon is displayed instead of a regular folder icon. Once you open your project, you can right click compile the project.
You don't use java compiler yourself to compile java files in a project. Compiling and building are done by tools like ant, maven... It's automated.
Importing existing projects into netbeans is a great way to loose a half a day.
I'm assuming that since there's a nbproject directory, this was built through netbeans, which should give you a leg up.
In the "Open Project" wizard, the top level of your application (not necessarily the sources) should have a friendly globe icon for a web application (.war) or a triangle for EE application (.ear). Open the triangle if there is one. Web applications can be packaged with EE applications through netbeans, so if the Web App you're trying to compile belongs to one, some of the build properties may be associated with it.
Looking at the file nbproject/build-impl.xml should give you hints about where your libraries folder was located. Make sure this path matches in your project properties under the Libraries header. These libraries can be shared among projects and therefore likely out of this projects directory structure and referenced or native to this project alone in which case jars are copied in to your lib folder.
There may be additional reference or server issues that netbeans detects (and gives a paltry error message for) which can be found in the project context menu under "Resolve Reference Issues" or "Resolve Missing Server". In netbeans projects are built against the servers they're run on right in the IDE. Check that you have the servers you want configured under Tools-> Servers, then ensure that server is linked in your project properties under Run.
This may not solve all your problems, but is a good start. Good Luck!