Running in intelij
When i try to run the .jar
Edit environment variable path
I've written my first small program in java, and want to make it into an executeable file.
I used InteliJ to generate a .Jar file out of the Main class. When i Run the Jar in Intelij it seems to work fine. However once i try to open it from my windows i get
error a jni error has occurred please check your installation and try again
Some googling told me that my JDK might not be properly set in my system properties, so i added the path to my JDK, however the error remains. Anyone have any idea what's up with this? I believe that I added my JDK through inteliJ. Why is it so difficult to simply run the program i made? Is there something wrong with my JDK? is my .jar corrupt?
I'm trying to bundle my jar file with a jre into an executable on mac so that users using my application don't need to have java installed on their machine. I'm using IntelliJ's built-in tool that automatically bundles the jar file into a platform specific package but whenever I try to build the artifact I get an error message of
jpackage: No archive found
I was able to create a bundled .exe file with the jar file on windows using launch4j but that tool can't create mac executables (unless I'm mistaken) and it would probably be more convenient to learn how to use the IDE to do it for me.
I can't seem to find out what it is I'm doing wrong, nor can I find anything online about this error message. Any suggestions? (I'm using java 16)
I was able to fix this problem by deleting and re-doing the configuration for the package artifact build. Everything worked smoothly afterwards
I've created a JavaSE app in Netbeans and am using Inno Setup 5 to generate what I thought was a complete Windows installation, including JRE. As instructed, I have checked the NetBeans property boxbox for Native, and have Inno Setup 5 in the Path. The EXE is generated and installs nicely PROVIDED the target machine has Java installed. If it doesn't, there's no file association with .jre and no javac.exe so the .jar file won't run.
3/4/2017: After lots of poking around and trying things today I now understand more fully what NetBeans Native packaging is really doing. It creates an Installer exe that, when transferred to and executed on a target machine with or without JRE, creates the actual myApp.exe and puts it on the Start menu. My problem has been thinking the myApp.jar file had the JRE in it, so I was just trying to double-click the myApp.jar. If I use the myApp.exe it works.
However, I now see I still have a problem. myApp requires a number of supporting data files and reading from an .ini file. Consequently, I'm going to have to create an Inno setup to do that stuff separately, and my users will have to download and run TWO installers, so to speak. Had the person who did the NetBeans Native installer thing made the Inno setup file accessible for editing, that would be neat.
Ed
NetBeans has a Packaging option for creating a "Native" application, i.e., a MyApp.exe file for Windows. The importance of this is you get a Windows executable the INCLUDES JRE, meaning that the ultimate user doesn't need to install Java or JRE on his/her machine to run the application.
This sounds wonderful, but the documentation is not at all clear about how to make it work, at least not to me. Here's what I've learned.
First, for this to work you have to have Inno Setup 5 or higher installed on you development computer. Apparently, NetBeans creates an Inno .iss file and runs it.
To understand it better I made a NetBeans projects for the Inno AnagramGame example. To enable the Native packaging option, first select the Project in NetBeans , right-click and select Properties|Deployment. Check the Native packaging box. This causes the EXE option to be placed on the NetBeans Packaging menu. I.e., Select the Project, right-click and click on Package As. Clicking EXE Installer launches the process of building the "package."
Building the installer takes a LONG time because it has to accumulate all the necessary pieces of the JRE and incorporate into the package. This also makes the installer BIG. Even for the smallest Java program it will be about 35 Mb.
After the Native packaging of some app, for example AnagramGame2, you will find the following in the NetBeans project folder:
C:\Users\Ed Sowell\Documents\NetBeansProjects\AnagramGame2\dist\anagrams.jar
and
C:\Users\Ed Sowell\Documents\NetBeansProjects\AnagramGame2\dist\bundles\AnagramGame2-1.0.exe
Anagrams.jar is the Java archive file for the AnagramGame2 app. IF YOU HAVE JAVA INSTALLED, this will actually run the project by double clicking. However, if you move it to another computer WITHOUT Java or JRE installed, it will not be executable. The reason is the jar file does NOT incorporate the JRE. It took me long time to recognize this.
Now, you might be thinking AnagramGame2-1.0.exe is the Native executable for the app but, nay, it is not. It is in fact the installer, another thing that took me a long time to recognize.
So, where is the fabled Windows Native app file? The answer is it is nowhere, yet. In order to get it YOU MUST RUN THE INSTALLER! After running it you will find the much wanted EXE in, of all places, C:\Users\Ed Sowell\AppData\Local\AnagramGame2:
C:\Users\Ed Sowell\AppData\Local\AnagramGame2\AnagramGame2.exe
Also, with the appropriate options selected, the app name will appear on the Windows Start menu and desktop.
So, to distribute the Windows Native application you have to:
Create a NetBeans project.
Do a Clean build of the project
To enable the Native packaging option for the project
Do a Package as|Native installer
Distribute the installer, in this example it is AnagramGame2-1.0.exe
Your user then runs the installer. Afterwards, he/she runs the app from the Start menu or double clicking the desktop icon.
There's still a lot I don't understand about the proper use of this NetBeans/Inno Setup process. There are some small mysteries, such as why it hides the location of the end product in User AppData Local. Who would have thought to look there? And why does it call the Installer AnagramGame2-1.0.exe instead of something like setupAnagramGame2.exe? But here's the biggest problem I've yet to solve: How does one install ancillary files needed by the app? Or get needed data out of an INI file? If the .iss that is built and used in the NetBeans process were made available it could be edited, but so far I've not been able to find it. My guess is it gets deleted. Short of that, the only thing I can think of is to write another .iss file to do that work. Unfortunately than means the user has to download and run two installers!
The problem with the NetBeans packaging mechanism using Inno Setup is that - AFAIK - you can't give your own .iss file to the build mechanism. NetBeans creates an own installation script file with little to no external influence.
The biggest problem I too have is that the package is installed (at least for Windows) in C:\Users\<user>\AppData\Local. Who on earth is going to look over there in the first place to find back an application??? Don't know why they've taken that decision.
Whenever you click the executable generated by NetBeans, you don't have any control whatsoever over location, shortcuts,... And that's too bad...
To overcome this, I did the following:
Allow NetBeans to do its job and create an executable installer
Once the installer is created, run the installer and let it install the app in the weirdest of all places on a Windows installation
Open Inno Setup Compiler and create your own installation script, using all the files and subdirectories that were created by the original NetBeans generated installation executable.
Generate my own installation executable using the above
Run the self-created installer: you now have all the options you want since you yourself created the installation executable (option to change installation directory, default installation directory, default installation directory name, use desktop shortcut or not, allow for all users or current user only, ...)
I know this is a workaround and a 2-way process but that was at the time I needed it the only(?) / best(?) way I could find.
In the mean time, I found an alternative way to create an installer executable on this page where you can create your own .iss file and as such, have much more control over what is going to happen.
I didn't try it out myself yet, but I think it has quite some opportunities.
I'm having a problem with the java library sikuli.
First I downloaded the sikuli setup jar and executed it. It created sikuli-java.jar and a libs folder (under c:/documents/sikuli). After that I created a project in eclipse, added the jar to the build path and wrote the code. The code worked when I ran it in eclipse. After that I created a runnable jar from it. I ran the runnable jar. It closed when it hit the sikuli code.
I want to export the app as a runnable jar and deploy it, without the users need to install sikuli. Is this even possible?
Also: https://github.com/RaiMan/SikuliX-2014/wiki/Usage-in-Java-programming
take care, that sikulixapi.jar is in the Java classpath of your project
I don't even have a file called sikulixapi.jar.
=======================================
Maybe a quick note, I've created the sikuli-java.jar with option 4 and 6.
edit:
Anyone? The application works fine in eclipse but when I export it as runnable jar and run it, as soon as it hits the sikuli stuff it closes. No catch block triggered, although I've surrounded the code with catch(Exception ex). I've configured eclipse like this: https://stackoverflow.com/a/10354759/2815780
This is RaiMan from SikuliX (http://sikulix.com)
-- 1. You currently are using 1.0.1. I recommend to switch to version1 1.1.0, since this installs smoother especially on Windows (no path entry or anything else needed anymore).
Since you want to deploy your app to systems not having SikuliX installed, this would make it easier.
-- 2. If you want to run your app on systems not having SikuliX installed, you have to pack a sikulixapi.jar (created with setup for the target system) into your application jar (make a so called fat jar or uber jar) or allow people to download a ready made sikulixapi.jar from somewhere and take care in your application, that sikulixapi.jar is on class path, when your app runs. What makes sense in your case, depends on how you want to publish your app.
-- 3. you say: The application works fine in eclipse but when I export it as runnable jar…
Inside Eclipse it takes car, that dependent stuff is on class path. The jar produced in the workspace though is "naked" and need a class path at run time.
There is an option, to copy the dependent jar to a lib folder in the workspace. If you do that, your jar will work (though I do not recommend this: sikulix jars should not be moved around but only referenced somehow)
-- 4. you say: No catch block triggered, although I've surrounded the code with catch(Exception ex).
If you run your jar from command line saying:
java -jar myapp.jar
it should crash with some unmatched exception (most probably "class not found")
As you already did, you might contact me directly with reference to this post here.
I've built a JAR file and it executes fine on my PC (XP) which has Eclipse installed. It also works on another PC, which also has Eclipse.
I've tried running it on another PC(XP) that does not have Eclipse. Though it contains the JDK and multiple JRE. The JAR file just does not execute by clicking or from the command prompt.
I am not entirely sure, but my best guess is the Environment Variables are not set properly. Here is the error I receive from the command prompt:
Exception in thread "main" java.lang.NoClassDefFoundError: ...
Any help would be appreciated.
It must be a CLASSPATH issue.
The stacktrace should also say which class it failed to find. Once you have that, then find which jar has that class. Then add that jar file to your classpath or add it to the classpath env variable.
This is likely a classpath issue as others have said.
One thing to note is how your jar is constructed. You have a number of options in the dialog for exporting a runnable jar;
Extract classes into jar
Zip dependencies into the jar - creates jar-in-jar-loader.jar inside the jar.
Place jars in a subdirectory next to the jar.
Depending on what you have chosen for this depends on how the jar will behave. If the classes are extracted, dependent classes not in the JDK should be on the classpath. I'd recommend this course of action as it is simpler.
Now, the question is - are you using a dependency on your classpath not in the build dependencies of the eclipse project? If so, it won't be packed with / zipped into / put next to the jar because eclipse doesn't know about it (but java will still find it on your system because it's on the classpath). Also, if you've saved an ANT script and updated the build path in eclipse, eclipse won't update that ANT script - that is generated once only.
Environment variables are not considered when invoking a jar file when clicking on it (equivalent to running javaw -jar your.jar).
I'm pretty sure that it doesn't work on your first PC outside of Eclipse either.