Where does the EMF Client Platform store local files? - java

According to this acrticle , the EMF Client Platform demo application stores the objects you create either in an EMFstore or in local files. As I do not have an EMFstore, I thought the application would store the information in .xmi files or something like that. Whenever I close the application and relaunch it, my created projects and objects are loaded correctly. But I can't find any files in my workspace! And I am sure that I'm looking inside the correct workspace because I use the -data flag to launcht the application and the .metadata folder was created successfully. Any ideas?

I'm not sure if this is what you are looking for, but my created objects are stored in a folder named runtime-EclipseApplication side by side with the workspace folder. I assume your "created objects" is referring to the modelInstances like "TournamentPro" or "League" in the given example article. If you do not have these folders, you should check again if you really do not have an EMFstore.

Related

Few general questions about "org.eclipse.wst.server.core" folder of a web application in Java

I have a few questions regarding the org.eclipse.wst.server.core folder in .metadata\.plugins folder in a eclipse work space. I know that while running an application in local host, this is the folder where we have to replace files for front end, like JSP, JS files, CSS files, HTML files, Images etc.
There will be some tmp folders into which I have to replace the files into respective locations. This folder will be having another folder with structure of a WAR file which I'll take from my work space and sometimes there will be multiple tmp folders like tmp0, tmp1, tmp2 etc (most of them having all required files). When there are multiple folders it is really confusing to decide that into which folder I need to replace the file(s).
Then I'll have to stop the server, kill all the java running in background (manually) and have to clear all the tmp folders (because if the java is not killed properly the jar files inside tmp's cannot be deleted saying its currently being used). I guess one among these tmp folders are used by the server to run the application.
After cleaning all the tmp folders if I start the server again, the first file created in that folder (org.eclipse.wst.server.core) will be one servers.xml, then one tmp0 will be created may be tmp1. When entire project is published only one tmp folder will be there, if I publish multiple times, another tmp folder will be created, may be 2nd time, 3rd time or nth time.
So my questions are
Is there a general name for org.eclipse.wst.server.core folder?
Why multiple tmp folders are created when publised multiple times? Can we restrict it into a single tmp folder?
After the project is published, is there a possibility that server will use multiple tmp folders for different request. Like for first request I uses tmp0 and when I refresh the page it uses tmp1 folder?
Edited regarding the 3rd question
I opened all the xml files in the folder given in the above image, and in tmp-data.xml, I found this content
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<temp-directories>
<temp-directory age="0" key="GlassFish v2.1 Java EE 5 at localhost" path="tmp0"/>
</temp-directories>
Where path attribute is given value as tmp0. So I'm guessing that will be the answer to my third question. I'm guessing this file will be created when there are multiple tmp folders, because after deleting all tmp folders and files in the folder and after publishing the work space the tmp-data.xml file was not present.
Edited regarding the WTP
I don't have much details about WTP, but when I clicked Help and selected About Eclipse in my eclipse I got this window
Not that I know of. It is created by WTP (Web Tools Platform) using WST (Web Standard Tools). If you find, let me know too.
That depends upon different checks that WTP and WST do before publishing the artifacts. It does not happen all the time, but it does a lot more than expected, because of file locks that stop eclipse from publishing a fresh copy of the application. And hence, the code must be trying to create new tmp folder just as a workaround. The metadata (publish.xml) is then updated, and everything works as normal, which I feel is much better since the developer does not have to know a lot of stuff about these failures. We can change this setting in the server properties in your eclipse. Note that different plugins have different ways of doing this, my STS has default deploy path set to wtpwebapps.
This must be available in your publish xml file. And it also depends upon the version of WTP / WST you are using. It is hard to see where the folder generation is happening (at least for me at this time), but you can look at PublishUtils.java and PublishDelegate.java in WTP. Github here.
No certainly not, after a project is published the whole server points to the location at which the artifacts reside. Though the context refresh might fail because of overlapping threads or wait time, it is not possible for two different instances to be deployed into the same server with the same application/context name.
Read this and this

Plugin Development, where to save user data?

I am developing a plugin for Eclipse. When the user runs the application for the first time, calibration takes place. This is where user data is taken and then printed out to text files, so that when used again, the system will remember their settings.
I was wondering where is the best place to store these text files on a user's system?
There are different options with different scopes:
per installation: see the post, create a unique folder under the mentioned path and store the files there
per user: create a unique folder under the users home directory (System.getProperty("user.dir")) and store the files there
per workspace: Plugin::getStateLocation returns a path that is unique to the given plug-in for each workspace. Store your files there. Plugin is an abstract class that is implemented by the Activator or your plug-in. If you don't have such class yet, create it by specifying the Activator in the manifest editor. Alternatively you can use Platform::getStateLocation() if you have a reference to the Bundle that represents your plug-in.
A common place to store such data is the
AppData\Local\YourPluginName
directory.
You may also use the
eclipse/plugins/YourPlugin
directory.
Your plugin can store data in the workspace metadata in the plugin 'state location'
Use something like:
Bundle bundle = FrameworkUtil.getBundle(getClass());
IPath stateLoc = Platform.getStateLocation(bundle);
stateLoc will be a directory where your plugin can store whatever it likes. The location will normally be '.metadata/.plugins/your plugin id' in the workspace.

Accessing folder in android

I am working on an android app in which I need to detect the language of user's input text.
So using Stackoverflow I found a recommendation of using a java library called langdetect which requires reading languages profiles.
I was able to create a simple plane java project, by adding a directory (folder) inside the java project called "profiles" which contains all the languages profiles.
I couldn't make this work in android since the only 2 ways I know of accessing files in android either by adding the desired files inside "assets" or "rec/raw" but I keep getting error saying file not found.
The method from langdetect jar file that requires reading profiles is the following
String path = "profiles";
DetectorFactory.loadProfile(path);
the above code works in plain java.
Any help guys.
I used the following
Uri.parse("android.resource://com.my.package.my.app/raw");
file:///android_asset
classLoader.getResource("profiles");
and many others in the same style.
The problem is that I don't need to access specific file per say, the only thing I need is a path to the folder that contains the languages profiles, the folder contains 53 files for 53 languages.
path is relative. It does not make sense in Android. You should refere the Internal/External storage with Absolute Path. If you put your data inside the sdcard, for instance, you can retrieve the Absolute Path with Environment.getExternalStorageDirectory(). If you want to embeded your data inside the apk, using the assets or raw folder, you need the AssetsManager in the former case, getResources() in the latter.

Locating created file with Java EE and Tomcat

I have created a dynamic web project, and use Apache Tomcat as a server.
In my servlet I'm creating a text file and want to reuse that in a JSP. However they are by default created in the installation folder of Eclipse when I do something as simple as the following:
File f = new file("test.txt").
I don't know why this happens. Is there a way to create the file in the WebContent directory as I want to make that file available for download in my JSP.
Java has a concept of the "current directory". When you start an application via Eclipse, this may indeed point to your installation directory. If you don't specify any path, a file will be created in this current directory. Hence the reason why your test.txt ends up there.
The WebContent directory is a something that is specific to Eclipse. Your code should not depend on putting anything there. You only start your application via Eclipse when you're developing it, not when you're deploying it to a live server.
The content of this directory will become the root of your .war, which is a well known location independent of how you start & deploy you app, BUT you still cannot depend on writing anything to this location at run-time. You might deploy your application as a packaged .war (likely for live deployments) or you may deploy your application unpackaged but then your application server may simply not pick up any changes done at run-time.
What you can do if you are sure your application only runs on a single server is writing the files to a well known location on your file system, such as /tmp, or /var/yourapp/files, etc. The code serving up those files can then pick them up from that location.
If you want to play it 100% safe according to the Java EE rules, you'd store your files on something like an FTP server that has a configurable address. Technically your war could be shipped between nodes on a cluster and requests could end up going to different machines, so depending on a local filesystem wouldn't work then.
Executing this statement this.getServletContext().getRealPath (""), you'll obtain the path where Tomcat WebServer is pointing at at runtime. You could add a folder "MyFolder" and call this statement:
new File(this.getServletContext().getRealPath ("") + "/MyFolder/test.txt");
Anyway, the default path looks something like:
...\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\<NameOfYourProject>
Note that when you create a new file, it won't appear in your immediate workspace (check the .metadata path), unless you change the runtime location tomcat should point at.

Java on MacOSX: how to access files in the bundle

I have a Java app which I am packaging to a Mac Application Bundle (That folder structure that contains all of the app but looks like a single executable file to the user).
My Problem:
I am reading and writing some config files in the local folder ("."). However, on Mac this seems to be the folder in which the application bundle is located (so usually the "Applications" folder and I obviously don't want that.
My question:
How can I store a file inside that bundle? How can I programmatically retrieve the bundle name to compute the fully qualified folder?
I know I could try to go the ClassLoader way, but I'd like to avoid that (for security reasons).
Or is there simply a better way how to store application cache and config data locally?
The Mac OS X Finder treats any directory whose name ends in .app as an application; right-click to Show Package Contents. It remains an otherwise normal directory for I/O purposes. This project is an example. See this answer regarding paths relative to the application bundle.
Addendum: Is there a better way how to store application cache and config data locally?
The example cited uses java.util.prefs.Preferences, but javax.jnlp.PersistenceService is an alternative.
Ok, the basic answer / solution is: don't do it.
The reason I originally wanted to do it was to cache larger amounts of data on the local HD. Java preferences are a good choice for config data (i.e. small data amounts) but fail to handle data in the megabyte size range.
My solution:
On MacOSX (System.getProperty("os.name").contains("Mac OS X")) I simply create a folder in the user's home folder (System.getProperty("user.home")). I prefix that folder with a . to ensure it is hidden from the user. This also ensures that I have write access to the folder (which could be a problem in the .app folder depending on where the user copies it)
On Windows (System.getProperty("os.name").contains("Windows")) I create that folder in the System.getenv("APPDATA") directory (note that this env variable only exists on Windows systems.
Now I have full access to the filesystem (even without admin rights) and can store as much data as I like.

Categories