Java .jar file, .txt file not changing - jar

I have a java program that writes text to a .txt file. I want to make a jar file so I can run the program without having to load up the eclipse environment. I have used the eclipse function to create a runnable jar file.
I double click this so that the program executes. Then when I browse to the text file in windows explorer its always empty. Why is this ?
When I run the program in the eclipse IDE and browse for the file it shows the text correctly.
Thanks All.

Related

Javafx project deployment - how to handle assets/resources?

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.

How to add new .java source file in Spring MVC project

I have copied a new .java file in relevant src folder. But, it doesn't appear in project explorer in STS4. No option in IDE to import file.
I know this is such a simple thing. Should have obvious options there. However I am not getting clue.
Press F5 or execute the menu item Refresh on the project once you have added a file to the project from outside the IDE, like on the file system directly.

JavaFX Application not loading fxml files when exported to a jar file

I have just finished my first java project, however I can't seem to get it to build properly. It will load the initial fxml file that the whole calculator runs on, however when I try to add a holiday/break in the holiday/break menu a dialogpane is supposed to display so the user can fill information, but I keep getting a location not set error when I run the jar file in the cmd. It all works when I launch it in intellij but not in the jar.
This is how I have my files set up. I made a resource directory in the FinishedCalCulator project and marked it as the resource root
This is how I set the Location of the FXML file into the loader. This works when I run it in Intellij but not in the jar file.
Project Structure
Running through CMD
Invocation Target Exception/Location not set error
I have looked around and found a few posts talking about putting all of the fxml files into a resource file and I did that and got it working again in Intellij, but it still will not display the dialog panes when I try to add them. I'm not really sure what I am doing wrong here. I don't think I fully understand what I am doing wrong. Any help would be great.
To expand on my comment...
Answer
In your code you are calling getResource("/addHolidayDialog.fxml"). Your resource's filename, however, is AddHolidayDialog.fxml. Simply change the "a" in your code to "A" and your code should work.
Explanation
Running from Intellij
When you run your application from Intellij it uses the output files in the out/production/classes directory. In other words, the classes are not in a JAR file. When you call getClass().getResource("/addHolidayDialog.fxml") you will get a URL like:
file://C:/.../out/production/classes/addHolidayDialog.fxml
Which works on Windows despite the fact the file is actually named AddHolidayDialog.fxml because Windows has a case-insensitive file system.
Running from JAR
Then you export your project to a JAR and run it from there. Calling the same getResource code you will now get a URL (if the code worked) like:
jar:file://C:/.../your-application.jar!/addHolidayDialog.fxml
What your code actually returns from getResource, however, is null. According to the JAR file, the resource addHoldiayDialog.fxml doesn't exist. It'll happily tell you that AddHolidayDialog.fxml does exist, however. The reason for this being that a JAR file has a case-sensitive "file system".

how to create executable file for netbeans project

I have a netbeans project(web application) including database connections, i want to get the executable file for my project (because i do not want to share my source code), which can run without the source code?
I have tried using jar,but extracting jar we get all the source codes.

Sublime SFTP - Upload compiled css when sass file saved

I'm developing html/css in Sublime. I'm writing my css with sass and using Sublime's build system to generate the css file on file save. It's also configured to upload on save using the SFTP plugin.
My problem is that the generated css file doesn't get uploaded as that isn't the file I've directly saved. I've tried to see if there is a way for the SFTP plugin to upload all files that have been modified locally, but it doesn't seem to support that.
Is there anything I can do to achieve this?
I'll throw my solution into the mix, just in case anyone stumbles on this as I did and wants to stick as close to a solely ST-based workflow as possible. If you're using the SFTP package for ST, there is an option to monitor files for external saves.
Unfortunately, using the ST build system to compile my SASS somehow slipped by SFTP. SASS CLI's watch utility, however, triggers the upload just fine. Once set, presuming the target file remains open, SFTP will upload it after each build.
To recap,
Open target file, followed by the command palette. Enter SFTP: Monitor File (Upload on External Save)
Start whatever CLI watch/build utility you prefer, for me, Sass: sass --watch app.scss:app.css
Leave target file open, otherwise the SFTP monitor seems to cease.
Enjoy!
NOTE: You can also enable file monitoring from the sidebar by right clicking on the file you wish to monitor and selecting...
SFTP has an option for that. Search on Package control for SFTP > Monitor file. Once selected, "SFTP monitoring" will appear on bottom command info. Now on every save, both sass and complied css will be uploaded to their respetive folders.
Because Sublime SFTP doesn't seem to support this, you'll probably have to go a different route.
I would recommend using something that monitors your css folder, and automatically uploads any changes to your server. Using good ol' fashion WinSCP (if you're on Windows) would work, but any way to sync folders works.
http://winscp.net/eng/docs/task_keep_up_to_date
I ended up scrapping SFTP and using ExpanDrive. Fits my workflow perfectly.
I'm still using Sublime SFTP to upload script files (js/css/php etc). Usually I press shortcuts to upload opened files (Ctrl Alt U + N). But it was annoying especially with frequent trial disclaimer window.
I wrote a simple tool on nodejs which monitors project folder and uploads any file on its change. It's not perfect but made my workflow much comfortable: https://github.com/liberborn/live-uploader.
Also note that you can map a local copy of your files to the remote copy, by opening the local folder in Sublime, then right-click on it in the sidebar, and select SFTP/FTP -> Map to Remote... to set up the connection, making sure to enter the appropriate remote_path to map the folder to.
Then you can do your build/compile, open the local compiled file(s), right-click on the code, and in the SFTP/FTP menu, select the Monitor File option.
Now when you build again in future, with the compiled file(s) still open, they will get uploaded to the server shortly afterwards (as well as being refreshed in Sublime when you switch tab to view them).
There's a way to force Sublime SFTP plugin to upload compiled files, if your CoffeeScript/Sass/Less files are compiled when you save a file.
Go to Sublime Menu → Tools → Developer → New Plugin..., and copy-paste the code below:
import sublime, sublime_plugin, re, os
class SftpAutoUpload(sublime_plugin.EventListener):
def is_remote_file(self, file_name):
while file_name != os.path.abspath(os.sep):
file_name = os.path.dirname(file_name)
sftp_config = file_name + '/sftp-config.json'
if os.path.exists(sftp_config):
return True
return False
def on_post_save_async(self, view):
window = view.window()
file_name = view.file_name()
# Upload compiled files to SFTP when saving a file (Coffee, Sass, Less)
if self.is_remote_file(file_name):
extensions = { 'coffee': 'js', 'less': 'css', 'sass': 'css' }
for extension, compiled in extensions.items():
matches = re.match('^(.*)\.'+extension+'$', file_name)
if matches is not None:
compiled_file = matches.group(1) + '.' + compiled
if os.path.exists(compiled_file):
new_view = window.open_file(compiled_file)
window.run_command("sftp_upload_file")
new_view.close()
Save the file as sftp-auto-upload.py. Restart Sublime.
What the plugin does is the following:
it checks if you're editing a CoffeeScript, Sass or Less file;
if a compiled file exists, then the compiled file is opened in Sublime
SFTP: Upload File command is executed, and the compiled file is closed.
All this happens almost instantly, so you don't even notice that a new tab was opened.
The code can be improved, but it does the trick.

Resources