I made an app using javafx and packaged it as exe file. It works fine being started from eclipse but being installed it says
Failed due to exception in main class
no matter what pc it was started at. I've found a few same questions but everyone found solution by themselves but don't tell how. One question has an answer:
the issue were VM parameters I added in the build.xml in the
fx:platform / fx:jvmarg section. These params were put into the
package.cfg file which is called from the .exe file to initialize the
VM.
In my build.xml there is only one string related to the named fx:platform But in my case there is only <fx:platform basedir="${java.home}"/> and nothing else. What am I doing wrong?
Related
Both class.getResource(FILE_NAME) and class.getClass().getClassLoader().getResource(FILE_NAME) run perfectly inside my eclipse but the same code getting failed to locate the file which is inside the jar file, when run as an executable jar in windows machine.
I have gone through all related links available for this problem (well, not exactly the same issue but 90% in sync), asked for solution but no reply came from any of those posts, so I'm posting my issue as a separate question hoping for help on this.
In total, 4 cases I have ran to resolve but none worked so far and I'm out of ideas now.
class.getClass().getClassLoader().getResource("/resources/readme.txt");
class.getResource("/resources/readme.txt");
class.getClass().getClassLoader().getResource("resources/readme.txt");
class.getResource("resources/readme.txt");
Ouf of all the above 4 cases, only 2 cases ran successfully in eclipse which are as mentioned below.
class.getResource("/resources/readme.txt");
class.getClass().getClassLoader().getResource("resources/readme.txt");
The other 2 cases just throwing me Exception in thread "main" java.lang.NullPointerException
Coming to the executable jar, all 4 cases are throwing me the Exception in thread "main" java.lang.NullPointerException.
So I have created a folder named resources where my jar is residing and placed my files inside this folder and ran the jar. Now the jar is running without any issues referring to the files inside the resources folder I created. So wherever I run this jar (windows, linux etc.,) I need to create a resources folder and place my files under the folder. Now the question is, can it be possible to make my jar refer the resources folder which is inside the jar itself?
Any help on this is much appreciated!
To get your txt file:
File yourFileIsHere = new File("resources/readme.txt");
Where put your file?
In the same location of your jar, example:
myapp/yourjar.jar
myapp/resources/readme.txt
If you want read file inside of your "src" folder:
InputStream yourInputStream = new YourClass().getClass().getClassLoader().getResourceAsStream("readme.txt");
If you are using Spring:
org.springframework.util.ResourceUtils.getFile("classpath:readme.txt")
Otherwise:
import com.google.common.io.Resources
byte[] byteSource = Resources.asByteSource(Resources.getResource("readme.txt")).read()
method class.getClass().getClassLoader().getResource() may take 3 prefixes: url:, classpath: and file: each prefix tells what is your base of search. If you want to search inside your jar use classpath: prefix. That tells your classloader to search everywhere within your classpath. Here is one example how to deal with it with Spring tools. Look also at ResourceLoader class in Spring
Here is the situation: I have a JavaFX8 application, made with Netbeans 8.1. The application runs/debugs within Netbeans without a problem. When I package the application as .EXE (or .MSI, same error), I get the .exe install file without errors. The installer installs the application with the expected folder structure:
+-- RCWStats
\+-- app
\+--lib (contains all needed jars)
\---RCWStats.jar
\---RCWStats.cfg
\+--runtime
\+--bin
\+--lib
\---RCWStats.exe
When I try to run the application by executing the RCWStats.exe file, I get these :
However, when I execute the RCWStats.jar in /app, it starts without errors, which I find puzzling.
I have found a similar question in SO, namely this one, but the solutions and comments in there didn´t help me:
I have executed the .exe from the command line, redirecting output, but the output file is always empty. I have triple-checked the main-class-setting in Netbeans, it´s correct. Also, my external libraries are generated correctly, so I don´t have to tweak my build.xml.
EDIT: additional info
I opened the JAR, the main class is where it is supposed to be. The manifest is also correct. Pic attached. To be honest, since the JAR is working fine, I suspect the problem is in the .exe, it somehow doesn´t find or execute the JAR correctly. Since the packaging process is more or less a blackbox, I´m kinda stuck.
Manifest-Version: 1.0
Implementation-Title: RCWStats
Implementation-Version: 1.0
Permissions: sandbox
Codebase: *
JavaFX-Version: 8.0
Class-Path: lib/eclipselink.jar lib/iText-4.2.0-com.itextpdf.jar lib/j
avax.persistence_2.1.0.v201304241213.jar lib/mysql-connector-java-5.1
.6-bin.jar lib/org.eclipse.persistence.jpa.jpql_2.5.2.v20140319-9ad6a
bd.jar
Created-By: JavaFX Packager
Implementation-Vendor: jalexakis
Main-Class: main.java.RCWStats
EDIT 2: RCWStats.cfg
[Application]
app.name=RCWStats
app.mainjar=RCWStats.jar
app.version=1.0
app.preferences.id=main/java
app.mainclass=main/java/RCWStats
app.classpath=lib/eclipselink.jar;lib/iText-4.2.0-com.itextpdf.jar;lib/javax.persistence_2.1.0.v201304241213.jar;lib/mysql-connector-java-5.1.6-bin.jar;lib/org.eclipse.persistence.jpa.jpql_2.5.2.v20140319-9ad6abd.jar
app.runtime=$APPDIR\runtime
app.identifier=main.java
[JVMOptions]
[JVMUserOptions]
[ArgOptions]
I would check the classes contained in the jar first and foremost and ensure that the RCWStats class is located in the right place. Check the manifest also to see what the main class is defined as and that it matches what you expect from NetBeans itself. And ensure that your runtime classpath is defined. Without seeing the contents of the jar, knowing your classpath settings, etc, it's difficult to suggest more. If you could embellish on these, perhaps it may become clearer and easier to answer? Thanks.
I'm producing an app using Eclipse on a Mac, and am using File Export to produce a Runnable Jar. The Runnable Jar files that I produce run happily on my Mac and on another Mac. But on two different Windows machines, they don't. I've looked around for answers, and have tried the following:
1) When I double click on the jar icon nothing happens.
2) When I type
java -jar Luscinia.jar
at the Command Prompt, I get:
"Could not find or load main class lusc.net.github.Luscinia"
3) When I type
java -cp Luscinia.jar lusc.net.github.Luscinia
I get the same error message.
The JRE on one of the Windows machine (at least) is up to date
(1.8.0_40). So is the JRE on the Mac.
The file structure inside my jar does indeed have
Luscinia.class nested inside github, net and lusc directories.
The manifest contains the lines:
Class-Path: .
Main-Class: lusc.net.github.Luscinia
(& it contains two blank lines at the bottom)
Other jar's are working well on the two Windows machines.
And to emphasise again, it works perfectly well on two Mac machines.
Any ideas?
I checked whether the EOL character had an effect. Changing it to Windows \r\n didn't have any effect. (Thanks to RealSkeptic for the idea).
Are you sure your class doesn't attempt to load a Mac specific class that is not available in the windows JRE (vendor private classes ? like com.sun classes on windows) or it's not missing dependencies in the classpath necessary to the main class ?
If one of your dependant class fails to load when the main class is being class loaded (in static blocks for example), it makes it fail to load the importing class as well and you can have that problem.
In any case, having the source of the main class could help figure out the problem.
The answer provided by DarkRift was correct:
Hidden in one file was a reference to a com.apple... class that was superfluous and, critically, platform specific.
In this case, when I got the error message:
Could not find or load main class lusc.net.github.Luscinia
It meant "Could not load" rather than "Could not find". Thanks for all your suggestions.
I'm trying to write to the Windows Event Log and I have a nagging issue.
First I created the NTEventAppender using steps found here.
How to create NTEventlogAppender.dll as required for logging event in the eventlog using log4cplus
I placed the .dll in the System32 folder. When I built and ran the program in eclipse I received this error
java.lang.UnsatisfiedLinkError: org.apache.log4j.nt.NTEventLogAppender.registerEventSource(Ljava/lang/String;Ljava/lang/String;)I
at org.apache.log4j.nt.NTEventLogAppender.registerEventSource(Native Method)
at org.apache.log4j.nt.NTEventLogAppender.<init>(NTEventLogAppender.java:79)
at org.apache.log4j.nt.NTEventLogAppender.<init>(NTEventLogAppender.java:49)
at mahle.eolx.ws.Main.<clinit>(Main.java:30)
Exception in thread "main"
Do I need to do something differently since this is a Java application and the question linked above was for a C++ Application.
And if that is the case, what do I need to do.
EDIT: I found out that I should be using the NTEventLogAppender.dll that was included with the log4j download, but I'm still getting the same error.
I couldn't get this to work, however I was able to log to the event viewer by using log4jna for the NTEventLogAppender (https://github.com/dblock/log4jna).
I took these steps
Download log4j and include the .jar file in your project http://logging.apache.org/log4j/1.2/download.html
Download log4jna which is used to replace the NTEventLogAppender and add the necessary jars to your project (log4jna, jna, platform) http://log4jna.codeplex.com/
You will need to add the Win32EventLogAppender.dll somewhere in your application directory.
To get the logger to log meaningful messages you will need to change the registry
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\"YourAppNameHere"]
"EventMessageFile"="C:\\Program Files\\"Your Application"\\Win32EventLogAppender.dll"
"CategoryMessageFile"="C:\\Program Files\\"Your Application"\\Win32EventLogAppender.dll"
"TypesSupported"=dword:00000007
"CategoryCount"=dword:00000006
I'm configuring the JPL right now, and wanna work with swi-prolog using java.
I downloaded the newest stable version of SWI-Prolog, which is 6.2.0, and installed in D:\swipl
First, I added the following path to the PATH virable: D:\swipl\bin, which should include all dll files needed.
Then, I added the following path to the CLASSPATH virable: D:swipl\lib\jpl.jar, which should be the jar file needed.
When I tried to run the versions example provided, I got the following error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: jpl.fli.Prolog.thread_self()I
at jpl.fli.Prolog.thread_self(Native Method)
at jpl.Query.open(Query.java:286)
at jpl.Util.textToTerm(Util.java:162)
at jpl.Query.Query1(Query.java:183)
at jpl.Query.<init>(Query.java:176)
at Versions.main(Versions.java:11)
After searching online, I found that many people just get java.lang.UnsatisfiedLinkError: no jpl in java.library.path which is because of the setting for the PATH variable, rather than the error I get here: java.lang.UnsatisfiedLinkError: jpl.fli.Prolog.thread_self()I (and yes, there is a "I" at the end of the line).
Has anyone gotten this error before? I've tried several previous version of SWI-Prolog, but also got other kinds of errors. I'm using Eclipse IDE for Java development -- have I missed anything?
I've sent the problem to the official mailing list (swi-prolog#lists.iai.uni-bonn.de) provided by swi-prolog.org, and luckily someone helped me to prove that there are some problems in the version 6.2.0. We then both tried the version 6.0.2, and it works perfectly. He mentioned that (and I noticed that) there is no swipl.dll in the bin folder of the version 6.2.0, which MAY causes the issue.
I've already reported the issue to the staff via Email, and at least for now, I suggest that people who want to configure JPL should download the version 6.0.2. Three things to remember:
add a new variable SWI_HOME_DIR under system variables in environment variables, and set the path to the place where you installed the SWI-Prolog (Mine is D:\swipl);
Add the path %SWI_HOME_DIR%\bin to your PATH variable, rather than use something like "D:\swipl\bin". (Otherwise [FATAL ERROR: Could not find system resources] will occur)
Add the path %SWI_HOME_DIR%\lib\jpl.jar to your PATH variable, rather than use something like "D:\swipl\lib\jpl.jar". (Otherwise [FATAL ERROR: Could not find system resources] will occur)
If you are using Eclipse for Java development, it seems that you DO NOT need to configure in your IDE. As long as you follow the 3 steps above and add the correct jar file as an external library, it should be fine.
I'm not sure whether the temporary solution works for everyone, but definitely, everyone who has the issue should try this method first. As long as the issue in the version 6.2.0 has been figured out, I'll add some comments here.
BTW, as far as I know, until now, people who have the issue are using 32-bit Windows.
Try adding your path to java.library.path via Run > Run Configuration > [project name] and add the following under "VM Arguments" tab.
-Djava.library.path="D:\swipl\bin;."
Furthermore, under the "Environment" tab, add the following:
VARIABLE: PATH
VALUE: D:\swipl\bin;${env_var:PATH}
After that, go to Project > Properties > Java Build Path, select "Libraries" tab.
Click "Add External JARS.." and find your jpl.jar.
Great Great Great, second answer is the solution
create SWI_HOME_DIR variable to set the swi prolog instalation directory
SWI_HOME_DIR ------- C:\Program Files\swipl
set PATH to point to the library and bin like this
PATH ------ %SWI_HOME_DIR%\bin;%SWI_HOME_DIR%\lib\jpl.jar
This fix my problem "Exception in thread "main" java.lang.UnsatisfiedLinkError: no jpl in java.library.path windows" it is a little bit rare but it works find.
I had the same problem. In addition to set the PATH, you need to verify if the installed SWI program has the same architecture (32 or 64) of your JVM.