I used to work on an IntelliJ project that was started before I started working on it. This project had a configuration that allowed me to generate an EXE file that could easily be sent to windows users.
It would generate a massive EXE file bundled with all the needed JARs of the application, and upon running it the first time, it would silently "install" itself into the AppData folder, as if it were a regular windows setup file, even though the user would not even notice it doing that installation.
I am trying to configure a project in IntelliJ to do the exact same thing, but first I have not been able to output the exe file by selecting "exe" as the Java FX native bundle type. It just generates a .jnlp and .jar file. When I select "all", as per some other post here in stackoverflow, it generates an exe file, but only with a few kb in size, which does not contain any of the .jar files that should be part of it. Moreover, when I try to open it, it just crashes saying the main class was not found.
Am I missing some setting for building the project? I am using IntelliJ 2018.3.2
Here are some screenshots:
I have been able to get past this error, after changing the verbosity of the compilation and going through the logs.
There was a log message which helped fixing this:
The process complained about the Inno Setup Compiler missing, which was right. Makes me wonder why IntelliJ would have that feature built in if it depends on external tools but does not notify the user clearly of this.
Detected [iscc.exe] version 0.0 but version 5.0 is required.
After going to the Inno Setup site, downloading and installing the tool, I was able to get the executable to be generated.
Now I am struggling with another error, which is the executable complaining about the main class referenced in the Artifact not being found, but at least I have moved past the first problem! Going to tackle this one now...
The best solution for this is using exe generator software.
There is plenty of exe generators out there.
EXE4J is the most simple & easy tool to use.
In EXE4J,
You can upload your main jar file and select the main class.
I think this will be solved your problem.
This may be due to you`ve extracted Jars to your output root, while you neet to Put it(you can check difference by deleting everything from your output root in Output Layout screen and then just right click on jar on the right side, you will see two options here, try another one
Related
I wrote a program in NetBeans, and now want to share it with my coworker. However, when he tries running it on his computer, he gets an error message:
"Could not find the main class: excelcomparator.ExcelComparator. Program will exit."
Here's the confusing part: I wrote this on my laptop which has NetBeans, and to make sure that it worked, copied the dist folder onto a flash drive, and ran it on my computer. It worked fine. When I emailed it to my coworker, he got that error.
Based on what I've seen, some solutions are to run the .jar from the command line. While that might work, I need the file to be double-clickable.
I sent my coworker the file via email in a zipped folder, is it possible that unzipping the entire folder also messed up the .jar file (don't see why it should, but included anything that might help)?
This is the MANIFEST.mf that's within the .jar file. There is a carriage return at the end of the file, it just doesn't copy well into this text box:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.4
Created-By: 1.7.0_71-b14 (Oracle Corporation)
Class-Path: lib/poi-3.12-20150511.jar lib/poi-examples-3.12-20150511.j
ar lib/poi-excelant-3.12-20150511.jar lib/poi-ooxml-3.12-20150511.jar
lib/poi-ooxml-schemas-3.12-20150511.jar lib/poi-scratchpad-3.12-2015
0511.jar
X-COMMENT: Main-Class will be added automatically by build
Main-Class: excelcomparator.ExcelComparator
I sent the dist folder, which includes the lib folder which contains all the additional .jars.
If there's any other relevant information I need to include, let me know. Thanks!
If you want the JAR to be double-clickable then you should bundle all the dependencies into a single JAR file.
You achieve this using the maven assembly plugin: http://maven.apache.org/plugins/maven-assembly-plugin/usage.html
If you don't know how to use Maven, Eclipse has a nice wizard. I'm not sure how it works on NetBeans but the same question has been asked many times, e.g. here Netbeans Export to Jar, include all library files
Just to finish this off, I'll write what ended up working for me:
As per Franz Becker's suggestion based on this question, I bundled the entire program into a single .jar file.
I was still getting the same error on my coworkers computer, so based on other suggestions I saw, I guessed that the problem was based on different versions of Java installed on our computers. What I did was recompile the program to an earlier version of Java, which works with any version from then and onward (other people suggested reinstalling Java on the users computer. That's a bit too unrealistic in most scenarios).
To change the compliance level (in Eclipse): right click on the project in Package Explorer, select properties. Choose Java Compiler in the options on the left. Uncheck 'Use compliance from execution environment [default target JavaSE] on the 'Java Build Path'', and change 'Compiler compliance level' to your level of choice (I picked the lowest option available, 1.3, as I assumed anything higher than that wouldn't be an issue).
I then exported the file (File -> Properties -> Java -> Runnable JAR File), and had a working, clickable .jar.
Thanks to everyone for their help!
I made a small application using Java Swings and then created a jar file of the project using 'clean and build' option in Netbeans. Then, I converted that .jar file in a .exe file using the software 'Launch4j' and it was perfectly running on my laptop. However when I tried running that exe file on other laptop. It displayed the error: Class NewJframe.firstfile couldnot be found.
( I made the database on the other laptop also with MySql Connection).
Please help me clarify why I am getting this error.
Also, I would like to know what all are the requirements to run an .exe file on other computer which I made from a .jar file?
I would pretty much expect something like Launch4j to take care of all your packaging requirements; did it give you options to "include all dependencies" that you didn't click "YES" to...?
It sounds like it's packaged your app, but possibly not the Java runtime envt it needs to run your app.
Try giving him the JAR file and see if he can run that. If he can, It's a problem with Launch4j, if he can't it's a problem with Java.
Alternatively try something like Excelsior JET instead.
Class NewJframe.firstfile couldnot be found
Launch4J only bundles your application's main JAR file inside the .exe (or not even that if you select "don't wrap JAR") - any other JARs that the main one depends on must be present in the same relative locations, you can't necessarily copy just the .exe.
I've created a game project in NetBeans 6.9, and I want to run the project on another computer. The problem is if NetBeans is not installed on the other computer then surely I cannot run the project.
Therefore I have to convert my project into a .exe that can be run on other computers without having to install NetBeans.
Is there a free application that can convert .java to .exe?
Please help me to convert my project into a .exe file. Thanks.
Check out these official netbeans article for Packaging and Deploying Desktop Java Applications and Developing General Java Applications.
From the article
Running the Application Inside of the IDE
When developing applications in the IDE, typically you will need to test and refine them before distributing them. You can easily test an application that you are working on by running the application from the IDE.
To run the AnotherGrep project in the IDE, right-clicking the project's node (AnotherGrep) in the Projects window and choose Run Project.
The xGrep window should open. You can click the Browse button to choose a file in which to search for a text pattern. In the Search Pattern field, type text or a regular expression pattern that you would like to match, and click Search. The results of each match will appear in the xGrep window's Output area.
Information on regular expressions that you can use in this application are available here and in many other places on the World Wide Web.
Running the Application Outside of the IDE
Once you have finished developing the application and before you distribute it, you will probably want to make sure that the application also works outside of the IDE.
You can run the application outside of the IDE by following these steps:
In your system's file manager (for example, in the My Computer window on Windows XP systems), navigate to PROJECT_HOME/dist and double-click the AnotherGrep.jar file.
You will know that the application has started successfully when the xGrep window opens.
If the xGrep window does not open, your system probably does not have a file association between JAR files and the Java Runtime Environment. See Troubleshooting JAR File Associations.
Distributing the Application to Other Users
Now that you have verified that the application works outside of the IDE, you are ready to distribute it.
You can distribute the application by following these steps:
1: Create a zip file that contains the application JAR file (AnotherGrep.jar) and the accompanying lib folder that contains swing-layout-1.0.jar.
2: Send the file to the people who will use the application. Instruct them to unpack the zip file, making sure that the AnotherGrep.jar file and the lib folder are in the same folder.
The users of your application should be able to run it by double-clicking the JAR file. If this does not work for them, show them the information in the Troubleshooting JAR File Associations section.
Also some third party tools like Launch4j may do the trick. For more information see this article on java-to-exe
See Launch4j. I dislike starting java apps with a batch file. This wraps anything from the root jar all the way up to a complete Java environment in an exe. You get your own icon in the system tray rather than the generic coffee cup. I've used it successfully on a project that has about 300,000 downloads, and it's never been the source of a reported bug. NB It does take some careful reading to pick the right options for your project. But you can set it up with the Ant build script in Netbeans to make the .exe automatically. Very nice and clean. My project includes native libraries. They work fine as well.
I think the NSIS will help you . Most of the applications using NSIS. Because it is open source.
Also there is a Eclipse plugin for NSIS to make the process easy.
http://hmne.sourceforge.net/
This is my first question, so apologies for any mistakes. I'll try and give all the info I can. Basically I've written a simple swing application which just loads in image into a JPanel and displays it. I'm using Netbeans 7.1 and I have the latest version of the Java SDK.
Anyway, I've used the "Build" feature in NetBeans 7.1 to deploy my application into a Jar file. When I double click the Jar File on my PC, it runs without a problem. However when I put it on other computers (Tested on 2 others so far, both with the most current JRE) it fails to open, citing the following error:
could not find the main class: swong.Startup. Program will exit
swong is my package name, and Startup is the location of my main method. I have checked the manifest file which is created with Netbeans' build, and it[the manifest] does indeed contain the location of my main method class.
From searching, I've come across similar issues in which the classpath is set wrongly, but I don't understand how this could cause my particular error.
If someone could help me, I would be over the moon. I've been studying java for a year or so, and I've got a good handle down, but I've NEVER been able to make a Jar that runs on a computer which wasn't my own. So, 10 points and thanks in advance.
xo.
EDIT: Thank you for the responses. I'm doing shift work and swamped, but I will test and poke with these responses tomorrow and provide more information. Thanks again. xo
I had d same problem while distributing my app. There is 1 solution that you create a batch file with 'java -jar AppName.jar' and asking user to double click on this batch file to execute your app. What i did was to provide a JRE installation exe(eg: jre_1.7.0) with your app.
Now create a Batch file (install.bat) in which write following commands
jre_1.7.0 -> this will install jre on user's pc
set path="C\Program Files\Java\jre_1.7.0\bin"
java -jar yourAppName.jar
Why i installed JRE because different people have different JRE versions installed. So this makes it difficult to set path to the installed JRE's bin folder & calling the 'java -jar' command. Hence as you know which folders your JRE installation will create hence it is easy to set path and execute your jar file with 'java-jar' command.
Check that your jar file has the following structure (at least)
jarfile.jar
|---------- swong
|---------- Startup.class
|---------- META-INF
|---------- MANIFEST.MF
It seems like the class "Startup" is missing. Maybe your jar only contains the .java files, not the compiled classes.
This error message can be a mistakable java7 error, when you try to start java7 compiled classes with a different Java Runtime Environment then java7. Have you validated, that your .jar is started within a Java7 environment on those other test machines? Sometimes it happens, that you have installed different versions of JREs and you might not be sure which one is actually started.
To check which enviroment is used, you can check in your registry for the following value:
HKEY_CLASSES_ROOT\jarfile\shell\open\command
this should point to your latest JRE. Or if you'd like to stay compatible to java6 as well, define the appropiate compile level in your build environment.
I've finally managed to create a Netbeans project out of an old standalone (not Web-) Java application which consisted only out of single .java sources. Now I have basically two questions regarding Netbeans Subversion interaction and application deployment:
Do you check in all the Netbeans project files into the repository, normally?
If I build the project using Netbeans (or ant) I get a .jar file and some additional jar libraries. In order for the app to run properly on the server, some additional config files and directories (log/ for example) are needed. The application itself is a J2SE application (no frameworks) which runs from the command line on a Linux platform. How would you deploy and install such an application? It would also be nice if I could see what version of app is currently installed (maybe by appending the version number to the installed app path).
Thanks for any tips.
No, not usually. Anything specific to NetBeans (or Eclipse, IntteliJ, etc), I don't check in; try to make it build from the command line with your ant script and produce exactly what you want. The build.xml is something that can be used for other IDEs, or in use with Anthill or CruiseControl for automated builds/continuous integration, so that should be checked in. Check in what is needed to produce/create your artifacts.
You don't specify what type of server, or what exact type of application. Some apps are deployed via JNLP/WebStart to be downloaded by multiple users, and have different rules than something deployed standalone for one user on a server to run with no GUI as a monitoring application. I cannot help you more with that unless you can give some more details about your application, the server environment, etc.
Regarding the config files, how do you access those? Are they static and never going to change (something you can load using a ResourceBundle)? ? You can add them to the jar file to look them up in the ResourceBundle, but it all depends on what you are doing there. If they have to be outside the jar file for modification without recompiling, have them copied with an installer script.
As for directories, must they already exist? Or does the application check for their existence, and create them if necessary? If the app can create them if absent, you have no need to create them. If they need to be there, you could make it part of the install script to create those folders before the jar files are installed.
Version number could be as simple as adding an about box somewhere in the app, and looking up the version string in a config/properties file. It has to be maintained, but at least you would be able to access something that would let you know you have deployed build 9876.5.4.321 (or whatever version numbering scheme you use).
Ideally, you should not tie down your application sources and config to a particular IDE.
Questionwise,
I suggest you do not. Keep you repository structure independent of the IDE
You might have to change your application so that it's structure is very generic and can be edited in any IDE.
Is this a web app? A standalone Java app? If you clarify these, it would be easier to answer your query.
We don't check in the /build or the /dist directories.
We tend to use this structure for our Netbeans projects in SVN:
/project1/
/trunk
/tags/
/1.0
/1.1
/binaries/
/1.0
/1.1
When a change is need we check out the netbeans project from trunk/ and make changes to it and check it back in. Once a release of the project is needed we do an SVN copy of the netbeans project files to the next tag version. We also take a copy of the deployable (JAR or WAR) and place it in the version directory under binaries along with any dependencies and config files.
By doing this we have a clean, versioned deployable that is separate from the source. Are deployables are version in the name - project1-1.0.jar, project1-1.1jar and so on.
I disagree with talonx about keeping your source non-IDE specific - by not storing IDE files in SVN along with you source you are adding extra complication to the checkout, change, checkin, deploy cycle. If you store the IDE project files in SVN you can simply check out the project, fire up the IDE and hit build. You don't have to go through the steps of setting up a new project in the IDE, including the files you SVNed, setting up dependencies etc. It saves time and means all developers are working with the same setup, which reduces errors and discrepancies. The last thing you want is for a developer to check out a project to make a small bug fix and have to spend time having to find dependencies and set stuff up.
To answer question #2 -- who's your consumer for this app?
If it's an internal app and only you (or other developers) are going to be deploying it, then what you have is perfectly all right. Throw in a README file explaining the required directories.
If you're sending it out to a client to install, that's a different question, and you should use an installer. There are a few installers out there that wrap an ant script and your resources, which is a nice approach particularly if you don't need the GUI... just write a simple ant script to put everything in the right place.
Version number is up to you -- naming the JARs isn't a bad idea. I also have a habit of printing out the version number on startup, which can come in handy.