how to remove invalid launch configuration from recent launches drop-down - java

I'm currently developing an Eclipse plug-in that adds its custom launch configurations, which are linked to certain Resources in the workbench.
Background: sometimes, the underlying Resource would change, making the launch configuration invalid, and should not be runnable
How do I programatically remove a launch configuration from the recent launches drop down?
I mean this little downward facing arrow:
This would show all the recent launch configurations that were launched recently.
EDIT: I'm currently trying to access the history via the LaunchConfigurationManager and I can't seem to find an API that can tell me where I can get the proper instance, currently everything is null.
SECOND EDIT: The LaunchConfigurationManager is part of an internal package, it should not be used.

Background: sometimes, the underlying Resource would change, making the launch configuration invalid, and should not be runnable
Why would you want to remove an 'invalid' launch configuration from the history but leave it intact otherwise? If it is invalid, remove it entirely or repair it. But that's just my two cents without knowing the details of your application.
If you are willing to take the risk and use internal API you should be able to get the LaunchHistory via DebugUIPlugin.getDefault().getLaunchConfigurationManager()lgetLaunchHistory().
But have you tried to remove and re-add the invalid launch configuration right away to just remove it from the history?
ILaunchConfigurationWorkingCopy workingCopy = launchConfig.getWorkingCopy();
workingCopy.delete();
ILaunchConfigurationType launchType = launchConfig.getType();
IContainer container = launchConfig.getFile() == null ? null : launchConfig.getFile().getParent();
ILaunchConfigurationWorkingCopy newLaunchConfig = launchType.newInstance( container, workingCopy.getName() );
// copy all attributes from 'launchConfig' to 'newLaunchConfig'
newLaunchConfig.doSave();

In order to reflect the deletion of a Resource it needs to be linked with the launch configuration, using ILaunchConfigurationWorkingCopy.setMappedResources(IResource[])
Afterwards, when you delete this resource from the workspace (whether also on disk or not) this will hide the launch configuration that has this resource mapped to it.
My solution was to include that method call in the performApply() method of the used AbstractLaunchConfigurationTab
Link for the ILaunchConfigurationWorkingCopy API where I found this
P.S. Now when a resource is deleted (but not on disk, you can try this with a Project with regards to a normal Java Launch Configuration) and then re-added, the launch configuration is back up with all past details

Related

saving images to static folder require refresh/reload the server to implement changes

I'm trying to save/load images in the resource/public/images folder of my spring boot project, but I faced a problem that all changes to this folder require to restart of the tomcat server but I need to implement all changes without restarting anything to avoid production problems.
I searched for a solution on the Internet and I reached to use additional tools that should be a solution to my problem so I used devtool dependency but I still have the problem.
I'm not looking for local changes on my IDE but I need a solution that can be work everywhere.
First of all the solution that you are looking for is not possible and should not be design like that. Think of it, when your application would be ready, it would be a jar/war (an archived library) deployed on production and its not expected that your jar/war has to have changed at runtime. The correct solution would be, on the same server where you would deploy you app, you can create a folder (may be in same directory where you place your jar) and in this folder you can manage your images and can be read from there. So try by creating a folder outside your app.
And for your local, devtool is basically consume the latest changes from code and helpful only for development as you don't want to restart the server every time when you make any changes in the code.

How to refresh static resources in Java Web Application?

I am developing an application that stores data dynamically and displays it as it is generated or uploaded. But the problem is when I am uploading any image then it should be displayed. It's path is also defined perfectly but until I refresh the whole application in eclipse it remains unchanged.
So to update application, I have to refresh it.
My application is Java based and is useing JSP and Servlet. Is there any code that can be used to update or refresh the application?
Right now I am doing it by right click -> refresh or directly F5 it.
Or suppose I want to create directory then where will I have to create it that will be accesses easily without refresh.
When I'll host my application then which place is better for to store data?
I know it's outside the web app but any specific place? Because there is no drive so how can I create or make directory and access that one in my code.
A solution to this is a design pattern called Observer. You should read about it.
Is there any code that can be used to update or refresh the application?
Right now I am doing it by right click -> refresh or directly F5 it.
I think you need to look into the workspace re-fresh option in Eclipse ( was made available from Eclipse version 3.7.x ). You can enable it in Preferences > General > Workspace and select Refresh on access or as per need you can change to whatever setting you require.
When I ll host my application then which place is better for to store data ? I know it's outside the web app but any specific place ? Because there is no drive so how can I create or make directory and access that one in my code.
The location of static content is best if placed outside of the scope of the project itself. Maybe some other directory on your server ( be it any directory ).
I can share what I have normally seen as a trend in different applications that I have personally worked on. We had a separate tomcat server that just hosted all static content ( all media ) and our web application accessed that static-server (as it was named) within a secured network. All hits to static content could only be made via our application server and thus all direct hits were either rejected or not entertained at all.
Edit
I would suggest using a an absolute path
and on windows environment
you will HAVE to use the drive lletter
and specify the path as X:\some\path
if you want to hide your letter drive
due to obvious security reason
I can suggest another idea
Idea 1 : Make a separate drive (lets call it drive F) and make a folder with the name of "static". Then in your application , you just forward all requests to file uploads using this path ( F:\static......) . I would advise loading the directory name from a property file instead of hard-coding it in your code
Idea 2 : If you cant make a separate drive, then make a directory namely "static" on the root of same drive ( C:\static ) . Make a user group and give him read/write permissions on this drive and revoke writing permissions from this user on all other drives ( just in case someone messes up with this user-group). Next do the same thing as above i.e specify this path into your application. One thing is that you would have to run your application with that specific user-group to ensure that the permissions security you have setup can be implemented.
Best practice is to store such data outside the webapp's tree to avoid issues on redeployment.
You can't serve these files directly though, commonly it's done by creating a servlet mapped to eg. images/*; that parse the request URL (eg ) and based on that url fetches and serves. You need to set the correct MIME type for the output, and streamcopy the requested file to the servlet's output.
A well explained example of such a servlet can be found on BalusC's blog.

update properties file at runtime

I have one Project (say A) which uses Spring. Project A internally depends on other project (Say B) for few Task. So B Project URL is configurable in server.properties file of A Project.
So now each time URL for B project get changed then I have to shutdown A Project, change the URL in server.properties file and then again start the server.
So I have requirement as to ask user to enter the new URL using GUI and change the URL at runtime.
I know it is possible to change the value of the property at runtime but it will be set only for that session and not an actual modification to properties file, and once the server is restarted again it will refer to old URL because actual changes are present in Session and not to actual Properties file.
my actual need is that changes should be reflected in properties file(for future restart of server it should work) as well as in beans configuration File(for current session - I am aware of how to do.)
Now my requirement is, whenever any changes comes in configuration then it should also physically change the properties file...is there any neat way to do this instead of reading File and search for that key and then replace substring.
Is there any third party api to do this nicely.
You can look at commons configuration. See file based save and reload here.
You can update properties file at runtime by using Commons Configuration API then get value by key. Here is good working example update and read properties
Hope this help!

create a run-only-once java application

I have to create a jar with a java application that fulfills the following features:
There are xml data packed in the jar which are read the first time the application is started. with every consecutive start of the application the data are loaded from a dynamically created binary file.
A customer should not be able to reset the application to its primary state (e.g. if the binary file gets deleted for some reason, the application should fail to run again and give an error message).
All this should not depend on the os it is running on (which means e.g. setting a registry entry in windows won't do the job)
Summarizing I want to prevent a once started application to be reset in order to limit illegitimate reuse of the application.
Now to my ideas on how to accomplish that:
Delete the xml from the jar at the first run (so far I came to the understanding that it is not possible to let an application edit it's own jar. is that true?)
Set a variable/property/setting/whatever in the jar permanently at the first run (is that possible)
Any suggestions/ideas on how to accomplish that?
update:
I did not find a solution for this exact problem, but I found a simple workaround: along with my software I ship a certain file which gets changed after the program is started the first time. of course if someone keeps a copy of the original file he can always replace it and start over.
Any user able to delete the binary file, will, with enough time, also be able to revert any changes made in the jar. When the only existing part of the application is in the hand of the user, you won't able to prevent changes to it.
You can easily just store a backup of the original jar, make a copy, use that for one run, delete, copy the original jar, etc. You would need some sort of mechanism outside the users machine, like an activation server. The user gets one code to activate an account, and can't use that code again.

How do I update the cache for an applet?

I am trying to update the cache for an applet. The applet properly caches, but afterwards, no matter how stale the cache is, it won't update. If I manually delete the cache, a new one will be created upon the next page load, and all changes to the .jar file I am trying to cache take effect. Having to do this, though, is not acceptable.
I have tried using cache_archive in conjunction with cache_version in my index file like so:
if (navigator.appVersion.indexOf("Win")!=-1){
var attributes = { id:'manager', code:'HardwareManagerApplet_FileWriter', width:1, height:1} ;
var parameters = {jnlp_href: '/java/HardwareManagerApplet.jnlp', codebase: '/java/hardwaremanager.jar', cache_archive:'hardwaremanager.jar', cache_version:'0.0.0.7'};
check = deployJava.runApplet(attributes, parameters, '1.6');
hardware_enabled = true
console.log("Applet started")
}
This is having no effect. I have tried moving cache_archive and cache_version to attributes and as various permutations between to no avail. I have tried enabling cache_option set to first browser, then tried again setting it to plugin. No dice. I've looked into ETags, and I'm not confident that will be the best solution. I've also looked into last-Modified, but A) I'm not sure how to implement it into the http so the cache will update and B) that will open a whole new can if I have to go that route.
Is there any other reasonable alternative? Better yet, am I simply implementing cache_archive et al incorrectly?
And actually, even if I can get it to cache every single time the page loads, I will be satisfied.
Thanks for all and any help!
Edit: The block of code about is the ONLY implementation I've made of cache_archive etc. Do I need to put in a couple lines elsewhere? As far as Oracle's documentation went, I didn't find that to be very clear.
Your missing the parameter for the cache option they are as follows
The cache_option attribute can take one of three values:
No - Disable applet installation. Always download the file from the web server.
Browser - Run applets from the browser cache (default).
Plugin - Run applets from the new Java Plug-in cache.
By defaulting to browser you would have to clear the browser cache for the updated values to take effect. Use plugin to take full advantage of the versioning you want to implement.
The caching of an applet is the work of both the virtual machine (JVM) and your browser. The browser as well as the JVM are optimized for caching applet for performance purpose.
My solution were one of both:
Clear the cache of the virtual machine after every classes build: open the Java console and type x (ClassLoader-Cache clear). Then refresh your browser.
or
Close your browser and start it all afresh
I prefer solution 1.

Categories

Resources