my web application project (JBoss AS) needs to read a file which resides outside of this project. For example, the file to be read is under /tmp/.
It looks like classes in the project can't access files under /tmp/. However, it can output to a file in /tmp/.
Is this normal? How to access /tmp/ directory in a Web application?
Use java.io.tmpdir system property.
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
//Use tmpDir to access files in tmp directory
Make sure there are unix permissions to read/write contents on tmp directory.
Related
Recently I encountered a problem when using exe4j to package the jar into exe. My xml configuration file is placed in the same directory of the exe, but after the package is completed, the exe will look for the xml file from the temporary folder.
These are the instructions in the exe4j help documentation
For some applications (especially GUI applications) you might want to change >the working directory to a specific directory relative to the executable, for >example to read config files that are in a fixed location. To do so, please >select the Change working directory to: checkbox and enter a directory relative >to the executable in the adjacent text field. To change the current directory >to the same directory where the executable is located, please enter a single >dot.
The error when i running the exe :
[ERROR] In Log's init,cann't read config file, file=/C:/Users/**/AppData/Local/Temp/e4jEA8.tmp_dir1543543191//sys_log.xml
Why is the program not looking for this xml from the exe's sibling directory, and how can I find it from this directory?
If you are using the "JAR in EXE" mode, use
System.getPrpoerty("install4j.exeDir")
to get the parent directory of the executable.
I have a .jar file executing on a aws ec2 instance which contains the following code:
List<String> lines = FileUtils.readLines(new File("googlebooks-eng-all-1gram-20120701-k"));
the file exists in projectname/res and also in /projectname directly. I included /res in the build path. Also I see that the file exists inside the jar file at the root if I export the .java file in eclipse.
If I run the jar localy on my pc it works fine. But if I run it on a ec2 instance it says:
java.io.FileNotFoundException: File 'googlebooks-eng-all-1gram-20120701-k' does not exist
How can that be?
On your PC it is reading from the actual file on the filesystem - that is what new File means - a file on the filesystem.
To access a resource in a jar file you need to call getResourceAsStream or something similar instead.
I shared a folder containing a .bat file which calls/run a jar file from same folder. I need to run that .bat file(present on remote system's shared folder) from my system. It run successfully if that folder is on my system but if i run the same file from shared folder of remote system it gives message "cannot access jar file."
Please help me.
Thanks in advance.
I created a jar file from a Java project. I can even run it now, but it does not save the serialization file that is stored correctly when I run the program from normal binary code outside of the JAR file.
Can’t you create new files when you have a jar file?
This is how I write the file:
FileOutputStream fileOut = new FileOutputStream("data/vocabulary.ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(this);
out.close();
fileOut.close();
My JAR file looks like this:
META-INF
MANIFEST.MF
name
stefankoch
…
where name/stefankoch/… is my project namespace.
I tried creating a data directory in the jar-file (root), but it did not work either. There also is a data directory within the directory the jar-file resides in, but that one is not taken either.
How can I allow jar files to create files?
basically, you should not add information entered by the user into a JAR file, they belong to the user’s home directory.
This can be read with
System.getProperty("user.home")
And files within the user home directory can also be used from within a JAR file.
I have created a Setup file i.e. setup.msi , this file contains a website installer
I have a License.xml file that I want to give to my client with the installer (setup.msi).
Before running the setup.msi , client has to make sure that the License.xml file should be in the same directory where setup.msi resist.
I want my setup.msi file to copy the License.xml file to the Destination directory (where website will be installed , this path will be prompted to user for customization)
I am using MSIFactory for creating setup.msi. I am not able to do this. I searched over net but did not get any accurate answer.
I am not familiar with MSIfactory, but in installshield what I would do is, call a batch script to do the copy and pass the target directory as a parameter to it. or use the 'XCopyFile' function to do the copying.