Javafx project deployment - how to handle assets/resources? - javafx

I recently finished my first JavaFX project and am ready for deployment. I found that when I create the jar file for my project my ide creates a folder with the jar and other necessary files. I noticed that when I run the jar in the file everything works fine. However, when I take the jar our of that folder and place it as a desktop icon, various resources no longer become available - I am assuming this is because the jar file and the various resource files are no longer in the same file path/folder. - Is this the correct assumption to make?
Regardless, I wanted to ask what is the standard method of getting JavaFX resources and the accompanying jar file to work when the resources are not located in the same folder?
Essentially, I want to have a clickable desktop icon that launches the app, which the jar file fulfills. But if I put that jar file in a folder with its resources to get the project to work properly then the user will have to press the folder and then the jar file in order to get the project to launch - which is very counterintuitive.
Any ideas on how this issue is handled?

The best way to do this is to create a shortcut to your jar file not copy it to another location. The jar file depends on these resources to execute especially if you used external libraries.
The other alternative would be to export your jar file with the libraries included in the jar. This however would make your jar very huge depending on the number of libraries you have.
I hope this helps.

Related

Where do I put my skin files for a desktop libgdx project

I'm using libgdx for a desktop game/prototype and I want to start getting into UI design.
I followed the answer here: Default Skin LibGDX? to download the necessary skin files but I'm not sure where in my project to put the ui directory with these files. I have tried to put it right in the project directory along side libs and src, so there's libs, src, ui, Referenced Libraries, and JRE System Library but when I reference the Skin with new Skin("ui/uiskin.json") it is throwing a filenotfound exception. Should this be down in my com. package in the project viewer in Eclipse?
I understand for an Android app you use the asset folder, but I don't have one in my project since it's a desktop app, even if I were to just add it.. I still don't know at which level unfortunately. This is probably really simple.
Thanks in advance.
The skin files are being looked up as "internal" files. On Android, this will look through the Android asset directory and CLASSPATH, but with the Desktop backend, only CLASSPATH will be searched.
To be consistent with the way things generally work in Libgdx, create a directory called assets next to the src and libs directories in your desktop project. Then put your ui directory inside assets. This isn't strictly necessary (see below) but will make your project a bit more compatible with other Libgdx code and projects. With an Android project the desktop assets directory is normally linked to the Android assets directory, but without an Android project you should create a regular directory.
If you used the Libgdx Libgdx "setup tool" the desktop project's assets directory should already be on the CLASSPATH. If not, you will also need to add this assets directory to your CLASSPATH: Right click on the project -> Properties -> Java Build Path -> Source tab -> Add Folder ... -> Select the assets directory.
To be clear, if you don't want to mirror the Libgdx conventions above, you just need to make sure the directory containing your skin files is on the CLASSPATH, then they will be found as "internal" Libgdx files (for example, you could add the ui directory directly to the CLASSPATH, and then look the files up without the explicit ui/ prefix).

Want to Make a Jar file

I've made a java application(it extends JPanel) and want to make it into a jar file.I have BlueJ and I used it to do so but after I make the jar file it doesn't open. Can anyone help?
Jar files are PKZIP packaged files which have specific folder structure and convention in it. It contains the compiled version of your java sources (*.java -> *.class) plus meta data. You can "open" it with any archive which can handle zip files especially if you append the ".zip" extension to the file name.
If you mean executing your jar by "opening" it, that's a different thing. You have to have a standard static main method in one of your classes so the JVM can find the execution entrance point. If you have that you can say "java -jar yourjarfile.jar", which will execute your class starting from your main. Note, that I assume that you have JVM setup well (I guess you have) and your environment variables should be configured too. In most cases, your jar refers to other jar files. You can provide access for those for the JVM through classpath.
Do you use Eclipse to write code? If you do, then it is easy to use Eclipse to create an executable jarfile.
Do you use a JFrame to present your JPanel? If you do not, you may have a JFrame, it is the "application window" where the JPanel will be presented.
JFrame tutorial:
http://docs.oracle.com/javase/tutorial/uiswing/components/frame.html
/Johan

Qt including resource directory structure inside executable

I'm using QWebView to run a web app. There are 650+ files. Placing the web app's directory in the source directory does not result in the executable bundling the directory.
How do I include the entire web app directory so that the executable will be able to render the files.
Note: I have currently added index.html as a resource, and can access it with qrc:// - But since I cannot add the entire directory structure to a qrc (can I?), the executable does not include the other files.
You need to put an XML node into the .qrc file for each file you want to use using the Qt resource system.
This can be done using a simple pre-build script. Take a look at qrcgen. Quoting the blog post behind this link:
The script I created, qrcgen, takes a directory and a prefix, recursively scans the directory and generates a .qrc file with the same name as the directory scanned. It has solved my problem, and I hope it can help others. It is also available via PyPI, just "easy_install qrcgen".
In order to update the .qrc file whenever your directory contens change, you need to include this step into your build process:
For C++/Qt projects, you can add this step in the build configuration in QtCreator or add in your qmake file a system(...) statement. Note that such commands aren't portable in general. (If it's not portable, you can put some operating system conditions around multiple commands.)
For PyQt/PySide projects, I don't know how to do this, but I'm sure you find a solution for this too.

How to *correctly* upload a WAR and its dependencies to Tomcat7 in Ubuntu

I would like to know how to upload a WAR file separated from its dependencies.
For example, you upload al the dependecies and leave them in the classpath
then you upload your WAR file without the dependencies packed in it.
When you are testing you servlet this is very useful as you don´t have to upload
a big WAR file with small changes everytime you need to correct something.
The problem is that sometimes it works and some other times it doesn´t.
So is there an official correct way of doing this?
Of course just packing everything into the WAR file does the job.
If your WAR file has dependencies that are outside of it, then you will need to restart Tomcat whenever you update those dependencies: there is no such thing as a CLASSPATH for a WAR file other than what the container builds for you (which will include the stuff in the webapp's WEB-INF/classes and WEB-INF/lib/*.jar, plus all the libraries guaranteed to be available by the container like servlet.jar, etc.).
Tomcat allows you to use a shared lib directory but that doesn't auto-reload when libraries are updated, which is likely to be causing the "inconsistent" behavior that you are observing.
The official correct way of doing this is to upload the whole WAR file: that's what they are for.

git + Flash Builder workflow: how do I set it up so git works smoothly?

I'm using git to track a project I'm developing in Flash Builder, and I'm wondering the best way to go about having it track it, especially regarding Flash Builder generated files, Compiler generated files, and source files that aren't necessarily flex files.
I had it set up to ignore all of the flash builder .project & debugging directories via .gitignore:
.actionScriptProperties
.flexProperties
.metadata
.project
.settings
bin-debug
and also treating any swf/swc files as binaries via .gitattributes
*.swf -crlf -diff -merge
*.swc -crlf -diff -merge
One issue with this setup is checking out this project and using
it in Flash Builder from scratch:
Flash Builder doesn't like it when
you have a project folder without
the .project files. Only way to
import the source into Flash Builder is to:
Create a new Flex Application
Smother the template files it
created (specifially APP_NAME.mxml)
with a git clone.
Where do I put libraries? From a git perspective, I'd like to have them in the lib folder of the repo so when someone clones the repo, everything just works, but from a local file system perspective I'd like to store all my libraries in a single location and use Flash Builder to reference them, as I may update the library or download a later version. Maybe I should put the libraries in their own repo and load them as a git module? This way I don't need to manually remember to update my Y library files in all X projects that are using them, edit: they will simply update when I update each projects' submodules.
And what about external swfs/flex modules? I've was sticking external swf files in the bin-debug folder for now so the SWFLoader class can find them, but because I'm .gitignoring the bin-debug folder, they don't come with the repo when it's cloned.
One final issue is where to keep the files for the server. Do I have them in a separate repo? I'm using php VOs' with AMFPHP so it's good to be able to edit the php files alongside my actionscript files in Flash Builder... but they don't belong in the project src folder.
The current solution I'm using is:
Creating a 'server' folder in the project root
Pointing an apache virtualhost at it
Setting the run/debug settings to http://APP_NAME.localhost
Then using the server folder as a replacement for bin-debug when the files get exported
The problem with this is I've got a big mess of compiler generated files, and non-AS source files in my server folder. It just doesn't seem like an elegant solution.
How do you set up git to work with flash builder smoothly? Could all this be resolved with multiple git repos/Flash Builder projects, or an ANT script or something?
Thanks.
I've found a good solution which avoids all of the horror of having untracked files and keeping a massive .ignore list:
CLEAN your projects before you git commit.
Simple as that.
Whether it be by Flash Builder or by ant, you should have the ability to clean anyway, so if you simply clean before you commit, the problem of generated files is solved. Duh.
In fact you could probably set it up as a git hook or something.
Typically for eclipse projects with any SCM, I initially check in everything including .projects, etc., but maybe except bin-debug in your case. Then just make sure that anybody who checks out the project never checks back in those .xxx files. For instance, when I use perforce, I first check out the .xxx files to a changelist that I never check in. Then check out the rest to a separate changelist.
Another tip is to use user defined library variables when working with build paths, etc.

Resources