I am trying to export my project as an executable jar file in eclipse.
My jar file looks like this:
\com
\de
\org
\res
I've got some xml files in the res folder and now I have some problems getting these files with the FileReader
java.io.FileNotFoundException: jar:file:\C:\Users\Patrick\Desktop\Brainwav3.jar!\res\de.xml (Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)
at de.brainwav3.language.LanguageHandler.load(LanguageHandler.java:98)
at de.brainwav3.core.Launch.main(Launch.java:24)
The path gets generated like this:
URL url = getClass().getResource("/res/de.xml");
FileReader reader = new FileReader(url.toString());
So I don't really have control over the path.
I resolved this problem with copying the required files next to the jar file and changing the url to another path but I want all ressources to be inside the jar file
Related
I'm trying to create a new JarFile using an existing File object but I keep getting a java.util.zip.ZipException: error in opening zip file.
I'm running the code below:
File x= new File("C:/Users/Priyanka/Documents/hello.java");
JarFile jarF = new JarFile(x);
when I run the code above I keep getting the error below:
Exception in thread "main" java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(Unknown Source)
at java.util.zip.ZipFile.<init>(Unknown Source)
at java.util.jar.JarFile.<init>(Unknown Source)
at java.util.jar.JarFile.<init>(Unknown Source)
at prioritization.cfg.Test1.main(Test1.java:12)
I have tried this code on different machines and different version of eclipse but I keep getting the same issue.
I'm have tried to research the problem online but most of the solutions are about trying to open an existing .jar file.
Any help would be appreciated.
If you check the JavaDoc for the JarFile type, you'll see that it's only used for reading existing .jar files.
The JarFile class is used to read the contents of a jar file from any
file that can be opened with java.io.RandomAccessFile. - https://docs.oracle.com/javase/9/docs/api/java/util/jar/JarFile.html
To create a .jar file, you'll need to use a java.util.jar.JarOutputStream.
I'm loading a Property file with the following method:
private final String utitt=Paths.get(".").toAbsolutePath().normalize().toString();//
...
properties.load(new FileInputStream(utitt+"/beallitasok/lang.set"));
...
This works fine within NetBeans without problems, but the jar file fails in command prompt:
java.io.FileNotFoundException: C:\java\IKE\dist\beallitasok\lang.set
(A rendszer nem találja a megadott fájlt)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.(Unknown Source)
at java.io.FileInputStream.(Unknown Source)
at IKE.IKE.fordit(IKE.java:1519)
at IKE.IKE.access$300(IKE.java:81)
at IKE.IKE$IngatlanokAblak.(IKE.java:9411)
at IKE.IKE.(IKE.java:544)
at IKE.IKE.main(IKE.java:697)
I've copied the "beallitasok" directory there (to c:\java\IKE\dist in my case), so the file is actually there. I'm using some files to translate certain strings and save/read some settings. I've checked whether i'm just blind, so just opened the file with a "more C:\java\IKE\dist\beallitasok\lang.set" command and it works.
Where or how shall i search for a clue? I'm not a pro, so thanks for any help.
PS: (A rendszer nem találja a megadott fájlt) = The System can't find the specified file. Translated from the Hungarian language.
Hello so I'm new with libraries and i followed a Youtube tutorial
https://www.youtube.com/watch?v=HRaJXVuZjRM
and he imports the libraries there and it works, i did too as he did and it works (when in eclipse), however the problem comes later, when i export the app (i always click package but have tried extract and doesn't work either), i cannot open the .jar file.
I have seen already countless threads with this problem, i searched on google and found this:
http://wiki.lwjgl.org/index.php?title=Setting_Up_LWJGL_with_Eclipse
which is basically what he did in the video, i open my manifest file inside of the jar file with 7zip and i get this:
``
Manifest-Version: 1.0
Rsrc-Class-Path: ./ jinput.jar jogg-0.0.7.jar jorbis-0.0.15.jar lwjgl.
jar slick.jar
Class-Path: .
Rsrc-Main-Class: com.tutorial.main.Game
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader"
And if i run the application with the console i get this error:
Sun Dec 06 16:42:40 COT 2015 INFO:Initialising sounds..
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.UnsatisfiedLinkError: no lwjgl in
java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at org.lwjgl.Sys$1.run(Sys.java:73)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
at org.lwjgl.Sys.loadLibrary(Sys.java:95)
at org.lwjgl.Sys.<clinit>(Sys.java:112)
at org.lwjgl.openal.AL.<clinit>(AL.java:59)
at org.newdawn.slick.openal.SoundStore$1.run(SoundStore.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at org.newdawn.slick.openal.SoundStore.init(SoundStore.java:292)
at org.newdawn.slick.Sound.<init>(Sound.java:54)
at com.tutorial.main.AudioPlayer.load(AudioPlayer.java:17)
at com.tutorial.main.Game.<init>(Game.java:41)
at com.tutorial.main.Game.main(Game.java:159)
... 5 more
``
I suppose it means that it cannot find the libraries and stuff but i have already tried creating a lib folder and a natives folder inside, placing the stuff there and changing the manifest into this:
"
Manifest-Version: 1.0
Class-Path: lib/jinput.jar lib/jogg-0.0.7.jar lib/jorbis-0.0.15.jar
lib/lwjgl.jar lib/slick.jar
Main-Class: com.tutorial.main.Game
"
But it doesn't run it either, i really don't know what I'm doing wrong...
I found a temporal fix for anyone with this problem, remove the natives from eclipse (the native link) and then export and use JarSplice to generate the .jar, if you are using music and cannot open it just open the .jar create the folder you used for your files in your workplace (mine was res) and then drag the music files in there instead of outside... this is temporal since I'm sure there's better ways to do it.
I'm trying to save my file into a perticular directory. but i get the below Exception
Exception in thread "main" javax.xml.transform.TransformerException: java.io.FileNotFoundException: D:\News\nxis\NewFiles\I0cbf74105a2d11e5b730aca98fc673fd.nxi (The system cannot find the path specified)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getOutputHandler(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
at org.NXI.CreateNxi.createFiles(CreateNxi.java:49)
at org.NXI.GetInput.main(GetInput.java:24)
Caused by: java.io.FileNotFoundException: D:\News\nxis\NewFiles\I0cbf74105a2d11e5b730aca98fc673fd.nxi (The system cannot find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
... 4 more
---------
java.io.FileNotFoundException: D:\News\nxis\NewFiles\I0cbf74105a2d11e5b730aca98fc673fd.nxi (The system cannot find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getOutputHandler(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
at org.NXI.CreateNxi.createFiles(CreateNxi.java:49)
at org.NXI.GetInput.main(GetInput.java:24)
Here the path that is available in real is
String output = "D:\\News\\nxis\\" + replaceGuid + ".nxi";
But i'm trying to add a new folder inside it. I'm using the below command
String output = "D:\\News\\nxis\\New Folder" + replaceGuid + ".nxi";
When i run my program with the second step. It throws me an error. please let me know how can i fix it.
Thanks
this will fix your problem:
new File(output).mkdir();
mkdir() creates the directory named by this abstract pathname.
Make sure that D:\News\nxis\ directory path is existing if not you have to create it.
My web application has a feature of uploading PDF files to the web that is executed the following proccess:
Create a folder which path is C:/resource/pdf/
Then write a PDF inside the folder
Is it possible for a web application to create a folder then write a PDF file inside it? I tried this and it is working perfectly fine, on my local. But when I deployed the app in the web ( free hosting ) there is an error:
java.io.FileNotFoundException: C:/resource/pdf/Daily News.pdf (No such file or directory)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at com.neu.als.thesis.web.controllers.UploadController.writeFile(UploadController.java:129)
at com.neu.als.thesis.web.controllers.UploadController.uploadPDF(UploadController.java:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
I know lines 129 and 71. I tested it again in my eclipse and it is working. Is there any restriction on web application when it is deployed or anything similar that preventing me to create a folder?
Depending on your permissions on the server and who's account the server is running under, you may not have permissions to write to that directory. Typically, the safe bet for saving a file to the server locally is to create a temp directory or something inside of your apps directory structure to put the files in. You should have permission to write to that directory as long as it's in your apps file structure.