FileNotFoundException error when using a runnable Jar File in Eclipse - java

I am working on an assignment that involves the use of 2 txt files and creating a runnable jar file. Part of the assignment involves creating a runnable jar file called Hw2.jar, exporting that file into the "first directory level", then going into run configurations in the arguments tab and pasting, "java -jar hw2.jar ct.search ct.corpus" (the ct.search and ct.corpus files are the txt files) Here is what it looks like.
Yet despite having completed the steps, I'm getting a FileNotFoundException Error, as detailed below.
Exception in thread "main" java.io.FileNotFoundException: -jar (The
system cannot find the file specified) 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
java.io.FileReader.(Unknown Source) at
edu.iastate.cs228.hw2.Console.main(Console.java:29)
This is my first time trying to use a runnable jar file within the run configurations, so I am unfamiliar with how exactly the process works. I would very much appreciate any help with this issue. Thank you.
EDIT: The jar and txt files are NOT in the src folder. They are inside of the project folder.

From your first screenshot, it looks like all of the corpus files and the jar are inside the src folder (you can confirm if this is the case if you collapse the src folder by clicking on the triangle icon). Use cut and paste them at the project level.

Related

Issues with creating a JAR file with Eclipse

I have to extract a runnable jar file from an Eclipse project. I know that choosing Package required libraries into generated JAR makes the jar file slower than choosing Extract required libraries into generated JAR, but the problem is that if I extract the libraries, rather than package them, the application doesn't start because of the following error:
Catched FileNotFoundException: C:\Users\rober\Desktop\palbo-natives-windows-amd64.jar (The system cannot find the file specified), while TempJarCache.bootstrapNativeLib() of jar:file:/C:/Users/rober/Desktop/palbo-natives-windows-amd64.jar!/ (file:/C:/Users/rober/Desktop/ + palbo-natives-windows-amd64.jar)
Exception in thread "main" java.lang.UnsatisfiedLinkError: no gluegen-rt 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 com.jogamp.common.jvm.JNILibLoaderBase.loadLibraryInternal(JNILibLoaderBase.java:454)
at com.jogamp.common.jvm.JNILibLoaderBase.access$000(JNILibLoaderBase.java:59)
at com.jogamp.common.jvm.JNILibLoaderBase$DefaultAction.loadLibrary(JNILibLoaderBase.java:90)
at com.jogamp.common.jvm.JNILibLoaderBase.loadLibrary(JNILibLoaderBase.java:328)
at com.jogamp.common.os.DynamicLibraryBundle$GlueJNILibLoader.loadLibrary(DynamicLibraryBundle.java:390)
at com.jogamp.common.os.Platform$2.run(Platform.java:249)
at java.security.AccessController.doPrivileged(Native Method)
at com.jogamp.common.os.Platform.loadGlueGenRTImpl(Platform.java:231)
at com.jogamp.common.os.Platform.<clinit>(Platform.java:183)
at javax.media.opengl.GLProfile.<clinit>(GLProfile.java:99)
at org.jzy3d.global.Settings.<init>(Settings.java:12)
at org.jzy3d.global.Settings.getInstance(Settings.java:21)
at org.jzy3d.chart.Chart.<init>(Chart.java:59)
Of course, all the required libraries have been added to the Eclipse project and thus the application perfectly works if launched in Eclipse.
Is there a way to avoid this issue? In other words, is there a way to make my jar finding all the required libraries even if I choose the option Extract required libraries into generated JAR or Copy required libraries into a sub-folder next to the generated JAR?
Additional info:
even if I choose the option Package required libraries into generated JAR, I need to have some .dll files (e.g. gluegen-rt.dll, jogl.dll, jogl_awt.dll, jogl_cg.dll) in the same folder of the runnable jar files in order to make it opens correctly. Moreover, the application takes forever to be initialized.
Summary:
Extract required libraries into generated JAR or Copy required libraries into a sub-folder next to the generated JAR: the application cannot be opened because of the above posted Exception.
Package required libraries into generated JAR: noteworthy performance issue.

Exporting executable jar changes directory of images

I have a problem exporting my Eclipse project to an executable jar. I think I do it right but the jar launches than aborts. So I tried with "java -jar nameofproject.jar" and it
says :
Unable to load image :/images/dialogs/server-database.png
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)....
So I decompressed the jar and looked at the directory structure within it and I was surprised to see that my "images" package was included in an unwanted "src" directory, making it impossible for the jvm to find them.
So here is the original project structure in Eclipse:
and here is the directory structure in the unpacked jar :
(the images directory is under the "src" directory which prevents the jvm from finding the pics)
Any idea about how to solve that ?

Exporting JAR from Eclipse

I've created a SWT application using eclipse. In the application I make use of Images with in the project. Now I build the jar file and run it in the command line I get the following error:
Caused by: java.io.FileNotFoundException: Images\Back.png (The system cannot fin
d the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at org.eclipse.swt.internal.Compatibility.newFileInputStream(Unknown Sou
rce)
Now I can see that the program cant read my Image but I would like to ask how to I include the Images in the jar file for everything to run smoothly.
Right click on your project, choose export.
Export -> Java -> Jar file
Choose the resources you would like to export, then click Finish.
If you need a runnable jar, just make sure the files are part of your project. For example make a folder called "Images". Then exporting a Runnable Jar should work.
That will get you the Images into your Jar file. Once it's there you will need to retrieve it using the method "getResourceAsStream". If you need help with that there are numerous good answers, here is one, Getting images from a .jar file.

Eclimd: Can't locate files when run from vim

I have an Eclipse project:
myProject/
|--src/
| |--MyClass.java
|
|--bin/
|--MyClass.class
|--data.dat
MyClass reads from data.dat. When I edit MyClass.java and run using :Java from within vim, I get a bunch of errors:
java.io.FileNotFoundException: data.dat (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:120)
at java.io.FileInputStream.<init>(FileInputStream.java:79)
If I navigate to myProject/bin and run the classes there using java MyClass, I'm able to read the data.dat file.
Where do I set the location of the files I'm trying to open so that they're relative to the compiled Java, not relative to my *.java files? It doesn't seem to be in the .classpath file.
As a secondary question: I'm having issues finding the answer to this because I don't quite know what to search for. java runtime file locations doesn't work. What keywords describe this problem so I can find the answer for myself?
This might be because the default path isn't the bin folder but the project folder itself. Try to move your file to the project folder or change its path within the program.
You could also pass the file via commandline arguments but this can cause some other problems as you might already know.

How to create an exe file in java

Hi I want to create an exe file for my java app.
I tried with some third party softwares JEXECreator, successfully created the exe file and its working fine in my system, when I tried with another machine, it’s not working. I got the following error
* The error occurred while running the application. The exit code is 0x10000223.
* Contact the vendor of the application for troubleshooting.
java.lang.ClassNotFoundException: com.sample.SampleMain
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.ucware.JEXEClassLoader.run(Unknown Source)
at com.ucware.JEXEClassLoader.main(Unknown Source)
**************************************
I know there is something wrong with the classpath which I set.
Actually I want to create the exe file myself without using any third party software.
I found the steps in lot of sites
Created the manifest file named Sample.mft with following contents
Manifest-Version: 1.0
Main-Class:
Class-path:
In this I have some doubts,
How the Main-Class should be added, with the full package name (com.sample.SampleMain) or the class name alone (SampleMain) or with the extension (SampleMain.class)
How the class-path should be added, I have 4 java classes and 2 jars in my project. How to add all these in the class path, and do I need to add the java jdk in classpath.
Where the manifest file should be saved
What should be the manifest file extension (mf or mft)
In command prompt from which directory I should create the exe file (from my project folder or src folder or the folder which contains all the java classes)
What’s the syntax should be used while creating jar in command prompt
(jar cmf Sample.mf Sample.jar Sample1.class Sample2.class Sample3.class Sample4.class jar1.jar jar2.jar) like this or (jar cvfm Sample.jar sample.mf *.class)
When I did something like this I am getting a jar instead of exe file, When I run the jar in command prompt using "java -jar sample.jar" then I am getting class not found exception".
Actually how to create an exe file instead of jar file, that means just by double clicking that exe file, should run my app in any machine.
Can anyone help me to do this?
Thanks in advance.
I use the Ant tool under Eclipse IDE to work with InnoSetup and Launch4J to create the EXE and its installer which it also manages the classpath...
A guide? You can refer to:
http://www.eteks.com/tips/tipCreationExe.html (in French)
Can't speak for JEXECreator, but I can recommend JSmooth (http://jsmooth.sourceforge.net/). I've successfully used it for several projects (e.g. this SWT based Java app).
Personally, I like JSmooth. That is just wrapping. This means it is still a Java application. When executing the exe, it will unpack the jar to a temporary folder and then execute it with javaw -jar ...
A second option is gcj. But that is absolutely a bad choice. That doesn't wrap the jar in an exe, but it really compiles it to native system code. But this slows down your application very much. You can check some results of my timing on this topic.
I had some positive experience with Excelsior JET. Unlike gcj it actually works and execution times are faster than that of an executed .jar file. The downside is that it's not for free.
Well I will recommend you to create one bash file instead of doing complex things and by double clicking on it you can run your application.Yeah but you cant change its icon but there are many free tools are available by using which you can easily convert bash file to exe.
To create an exe file, I use launch4j. Launch4j converts the jar file into exe file and if I wanna pack it for the installer, I use InnoSetup. For me, that exe created by launch4j works on pcs.

Categories