Since Windows 7 the directory windows/system32/drivers/etc is specially hidden. Windows 7 itself doesn't show it, but it is there if I open it manually.
Today I was playing around with a Java JFace Eclipse example (http://www.ibm.com/developerworks/library/os-ecgui1/) and was wondering that java also doesn't show the etc directory.
So how can I get all directories/Files, when using file.listFiles() ?
Any ideas?
The File.listFiles() method should include normal "hidden" files in the result. If it does not, it is because of something going on at the operating system level to hide the files from the application (and not just the user).
I could not find anything in either java.io.File or the Java 7 java.nio.* extensions that mention accessing "specially hidden" files.
It could be a privilege related thing ... and if that's the case the solution is to execute the Java application with elevated privileges.
But the simple solution is for your application to keep its nose out of the Windows drivers directory tree.
As I wrote, I played around with an JFace Example, that builds up a Java based Windows Explorer.
I agree with you, that a Java application should normally not do something in the Windows driver directory tree.
The "specially hidden" files there, are visible with other programs like Total Commander without running this programs with other then normal rights.
I assume, that Windows has some API functions to get that information.
I'm just interested in a Java based solution that can show me everything, that's on my disk...
Related
i am currently writing a game on javaFX and i have plans to post it in the website i run in the future (end exploit the Ads while at it). The problem is that after searching around a little it seems there is no way to run a java application on a browser.
Allowing people to run it through the browser would really help sharing the program.
My question is: is there today(2018) any way to run a java application through the web? Though i like java, no browser support seems like a really, really bad idea.
Oh, i also heard of Java Web Start. Although it looks like it is just avoiding the problem (not running in the browser) it seems like a good way to share an application. The problem is that it seems it is (Will be?) deprecated? I am helpless, it is like java isn't even trying anymore...
PS: If it makes any difference my game would be a 2D game with 3rd person view. It will also require some server stuff since players will create "arenas" that others can challenge. I would say my game wouldn't be "simple".
Java Web Start does the job very well—if you are willing to pay for a code signing certificate. (They’re a lot more expensive than regular SSL certificates.) The idea is that a user clicks on a hyperlink on your page, which causes the user’s Java installation to launch your application (possibly after installing it). This requires users to have Java installed beforehand.
If you don’t have the resources or desire to go with a code signing certificate, you can look at https://docs.oracle.com/javase/9/deploy/self-contained-application-packaging.htm. It allows you to create native installation packages for JavaFX applications. The disadvantage: You need each platform to create an installer for it. Meaning, you need Windows to create a Windows installer, OS X to create an OS X installation image, and Linux to create a Linux package. Some may also require signing using native tools.
Java 9 includes the jmod and jlink tools, which are capable of creating a file tree with an executable shell script or .bat file. A major advantage is that you can build such a tree for any platform, regardless of your own platform, if you unpackage the foreign platform’s JDK on your machine. Another advantage is that the user doesn’t need to have Java installed at all. A disadvantage is that the script requires a terminal, unless running on Linux.
Of course, you can just go the manual route and distribute a zip file which contains your .jar file(s), a shell script you’ve written, and a .bat file you’ve written. It’s not elegant, but it’s better than nothing. But it may trip up some non-technical users.
There exist a number of tools which create a native executable from .jar files, but I am not familiar with them (and I prefer to avoid third party tools unless they are truly necessary).
Whatever approach you choose, the answer is the same: You distribute something on your web page which the user downloads and runs. Aside from the download process, the browser is not involved.
What you can’t do is have users run your application inside the browser. That is deprecated, with good reason: It’s a disaster for the browser performance, for the Java runtime, for security, and for the user experience. And Firefox has all but banned plugins, so you’d be locking out a substantial percentage of users.
Goal
I'm currently developing an application in Netbeans using the Netbeans Platform on Windows (a cross-platform solution would be wonderful but something hacky for Windows if required is fine for now). The application communicates with a native C++ DLL through JNA. The DLL sits in a specified directory which I cannot control or change - say C:\DLL.
The DLL itself loads some files for reading in values etc. but it does this using relative paths. So it requires the "current" directory to be C:\DLL. Again, this is something I can't change in this project. The DLL is something I have to communicate with as is (unfortunately).
Problem
For regular JAVA applications I've had the option in Netbeans to set the working directory of the launched application like shown below:
http://i.imgur.com/3HuQKS8.png
But in the Netbeans Platform framework/template there are no such options. For the most part it looks like Netbeans just makes the directory of the current file I have focused in the Editor pane to be the Current Working Directory.
So how do I go about doing this? I might be able to run the application through a shortcut that sits in C:\DLL but this doesn't help when I'm debugging the application through Netbeans.
I want to know how I can run/debug this Netbeans Platform application with the current working directory set.
Clarifying Netbeans Platform
The Netbeans Platform is an application framework of sorts. Has a pre-defined structure based on "modules" that interact to form the full application. The whole thing is hosted inside the Netbeans Platform environment which provides each of your modules with tabbed/docking windows. Kind of nice to develop larger applications.
More information here: https://netbeans.org/kb/trails/platform.html
I've resorted to using chdir as #technomage (I can't seem to upvote his/her comment with my current account status) has also suggested.
To do this, I used the following piece of code before I load up my C++ DLL through JNA.
NativeLibrary clib = NativeLibrary.getInstance(null);
int result = clib.getFunction("_chdir").invokeInt(new Object[]{"<PATH GOES HERE>"});
Source: https://www.java.net/node/643965#comment-821128
You can also check the result by checking the result variable. Should be zero if everything went well.
I am not quite sure why null works for NativeLibrary.getInstance. The documentation doesn't say anything specifically about this and I haven't been able to glean anything from the source here: https://github.com/twall/jna/blob/master/src/com/sun/jna/NativeLibrary.java - But passing null does seem to get you the default libc or equivalent for your platform.
Note also that I had to add an _ (underscore) to the function name. This has to do with how function calls get mangled when compiled on Windows. As far as I know, this isn't required on other platforms, but I don't have the ability to test this right now.
Since I was unsure about whether my call was actually working, I did the following first:
Function f = clib.getFunction("_chdir");
This returns a function "pointer" f that you can trace/debug to see if you have a valid reference. Luckily, in my case, all I had to do was add the underscore as was suggested in the source link above.
After this call to chdir, the C++ DLL I need to access has been happily accessing files relative to the location specified in chdir.
Is there a way to change working dir for JVM when running Java Webstart?
When i use system.setProperties("user.dir", newDir) it sets it(system.getProperties() shows it does) but ignores it.
Is this a limitation in Java Webstart to always use the working dir where i started the jnlp file?
I am using all permissions in the jnlp file.
Please help!
EDIT: Whatever i do now, my webstart always uses user.dir to save files. Frustrating!
I've had this question in the past myself, but I've always found that, in the end, I didn't need it. Why do I say this?
Because your java web start app is not like an executable run from Program Files. It doesn't even exist on your computer like most programs (it is broken up into a bunch of different files and reassembled by the JVM). Therefore, you cannot say that the program has its own directory to do what it needs.
But it doesn't need to. Here's why:
Java has the Preferences API to help when you need to store data. The under-workings of the Preferences API is as mysterious as JWS, thus they are really a perfect fit. Either way, if you need to write things to a file, you should check this API to see if it can meet your needs.
If you need to write files for the user, then prompting them and allowing them to choose the location obviously means you won't use your current working directory to read/write files.
If you need to serialize objects, you should just create a program directory using the user.home resource as #AndrewThompson suggested. This will be "your" directory and is as good (in fact, better) than a directory in Program Files (if you're running on Windows, as an example).
In conclusion, in all cases (that I've come across), there's no need to change your current working directory. If you need your own folder, create one in user.home (because you won't run into file permissions issues there).
..all my settings file i use is created in the user.dir.
There is the mistake. Put them in a sub-directory of user.home & the problem is solved.
In the hypothesis you really really need to divert user.dir property for Java WebStart execution, here is the only option I have found: set this system environment variable (so system wide):
_JAVA_OPTIONS="-Duser.dir=C:\Temp"
But care about it, this option is read and applied to any JVM executions.
Why was it required in my context ? Because Java WebStart ClassLoader was looking for any single resource (class, properties...) in user profile before getting it from jar files in cache. As the user profile has been moved to a network storage, application start up became terribly slow. I am still investigating Java sources to understand (and avoid) this behavior. So my applications work perfectly without setting user.dir but that was the only work-around for the performance issue we got at the moment.
The recommended way to pass runtime parameters or user specific setting is through the jnlp argument
<application-desc main-class=".....">
<argument>user.home</argument>
..............
I'm restoring an antique vehicle and for that I use the EPC (Electronic Parts Catalog) from Mercedes Benz. (Membership is free, so those wanting to see the program I'm talking about can go here if they want to check it out.) To get to the program, there's a sign in page, then another page with a link. Clicking the link downloads a file called ewa-net.jnlp and it's launched with JavaWS.
I used to use this program on my Linux system and it worked. I remember I changed either the osname variable in my /etc directory or I changed the OS in Firefox before I ran the program and changed it back when I was done, so it wouldn't effect any other Java program. The EPC program worked just fine under those conditions. I strongly suspect the reason for requiring Windows is more of a defensive move (for example, to avoid liability or to avoid having to fix bugs on multiple OSes).
I'm aware that making changes like this can mess up a program, but this is used only to go through the parts catalog and to examine part diagrams, which helps in determining part locations or placements or helps the parts guys because I can help them find the page a part is on quickly if I've done my research before calling them. I'm not saving data or modifying anything on a disk drive or elsewhere (although I do sometimes take a screenshot and print it out).
I cannot download ewa-net.jnlp and just run it whenever I want. I have to go through the HTML login page, then run the program from their site, so I can't just run the program from the command line or something like that. (Unless that replaces running it with JavaWS right after I log in.)
Now I'm using an iMac, using Snow Leopard. I tried finding and changing the osname on here, and it didn't work.
Right now whenever I need to use the EPC, I have to start up a Windows VM in Parallels and about the only reason I use that Windows VM is for this program.
Is there some way I can trick Java so when I run this program, it thinks it's on Windows? I'm aware this could crash, but since the catalog worked fine on Linux, I want to at least try it on OS X.
I thought maybe I could use a wrapper script that runs JavaWS, but I'm not quite sure what to do and, as I said previously, changing the osname setting didn't seem to work.
Is there anything that might help me trick this program into thinking it's on Windows?
It depends on exactly what is applying the Windows restriction.
It is possible for a JNLP file to specify elements for specific operating systems only, thus effectively restricting it to a particular OS. So if the JNLP file contains something like this...
<resources os="Windows XP">
<j2se version="1.5+" />
<jar href="/example.jar" />
</resources>
...then that could be what's preventing you from running it on Mac OS X. Have a look at the JNLP file (I'm unable to see it, as a non-US resident I can't sign up myself) and see if that's the cause. If it is maybe you can edit it. Why is it that you said you can't download ewa-net.jnlp? If you can download the JNLP file, edit it to have os="Mac OS X", then double-click it to run it (or right-click and choose Open With > Java Web Start).
Alternately, the reason why changing osname didn't work for you could be that you changed it in the wrong installation of Java. Apple moved the installation location of Java sometime (I think) after Snow Leopard was released. So you may find your installation in either of these locations:
/System/Library/Frameworks/JavaVM.framework/Versions
/System/Library/Java/JavaVirtualMachines
If you only updated one of these locations, you may have to do it in the other location too.
I have written a very simple Java application. Can anyone tell me how to create a launcher like icon to run that application both in Ubuntu and Windows ??
Thanks in advance..!!
An executable JAR should work fine for a launcher on both Windows and Linux. However, that won't get you a custom icon.
On Windows, you can use JSmooth, which will create a .exe wrapper around your JAR file. The JSmooth program will let you create an icon for the EXE as well (it also has options such as getting the user to download the necessary version of the JVM, or only permitting one instance of the program to run).
If your java application is to be distributed from a web server, you should have a look at Java Web Start which can do what you ask for based on a JNLP-file. Notably see
http://download.oracle.com/docs/cd/E17476_01/javase/1.5.0/docs/guide/javaws/developersguide/faq.html#104
Ubuntu and Windows will both have different ways to launch the application. I see two routes to follow here. One is to use Java Web Start and use a web interface to start your application. The other is to search for some sort of 3rd party installer that will create setup/installation programs for all the platforms you want to use.
I actually used a third party install program before, InstallAnywhere, but it was almost ten years ago. It offered the functionality you are looking for, though.
There are different ways to do this, sometimes the simplest is the best approach. One solution as suggested is a simple starting script. Roll your application into a jar, then include a script that does nothing more than "java -jar myscript.jar". I do this all the time for internal customers that may be running various types of *nix and whatever version of windows (a few macs as well). How sophisticated you need it to be depends on the audience served.
Create a bat/shell script which starts your application.
And than create a shortcut/launcher for it.
Shortcut file in windows has extension lnk.
Update
See example - SQuirreL launch file.