launch4j-maven-plugin windows 7 file associations - java

I created my java application as EXE file, everything works i can open it etc, my problem is that i want to use this EXE as default application for .ctr files, when i try to open that file in Windows Explorer, it doesn't do anything, no log is being created, it looks like it did not even try to open anything.
In the application, I am taking arguments from main method and creating files from it.
How can i even debug to find out what is going on.
I think that the arguments should come by as normal as you would execute app.jar -jar arguments here.
What also strikes me is that if i use terminal to open exe with argument for the file i want it opens and works correctly.
The problem seems to be more associated with Windows in my opinion, I tried to delete file association from registry for the .ctr file and explorer no longer showed any associations, but when i selected open i have seen my app in recommended programs.
This also worked for me for the first time, but then i had to move the app exe files into different directory and it looks like it did not update in windows or something so it may point to the old directory which doesn't exist anymore.
I also tried to write simple .bat file which starts the exe and pass parameter into it, this also doesn't work, it only shows terminal windows for milliseconds and closing it so quick, that i cant see what is going on there.

Launch4j only creates an exe which wraps around your jar files. For file associations, you'll need to edit the registry.
I would recommend using tools that will create and installer or your exe and then also make changes to the registry during installation.
Inno Setup Compiler is a very good tool to create windows installer.
Here is a quick start tutorial.
To create file associations, refer to these answers on SO
inno setup file association
How to change file associations in Inno-setup

Related

NetBeans and Inno Setup don't produce a proper Native .exe

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.

How do I debug an external .jar file through eclipse?

It's hard to explain, but I'll try my best.
There's a .jar file that opens up a GUI for a tournament environment. It's independent and I'm not given the source code. I need to code an agent in Java that competes in the tournament. When the .jar file opens, I can specify the path to my agent's class files in the GUI. This works fine. But I'm not sure how to debug this because the .jar file doesn't open in eclipse. I tried using external tools, which seems to run the .jar file but the GUI doesn't open up, so I can't specify the path to the agent. The tournament environment documentation doesn't really provide instructions to operate it without the GUI, so I really need to use just the GUI. Any way I can run this file through eclipse, so I can see how my own agent works with the environment and test/debug accordingly?
Additional info - this .jar also acts as a library which I was able to import into Eclipse without any issues.
It's hard to tell all of what's going on here, but there are a few things that can help.
First, you can start your app with the jar using command-line options like this:
-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8453,server=y,suspend=n
Note that if you need to debug the startup code, you'll need to set "suspend=y", so the app will pause startup until you connect from the debugger.
In Eclipse, connect on port 8453.
Second, stepping through code that you don't have the source code for is not insurmountable. Install the "jd-eclipse" plugin, which you can get at http://jd.benow.ca/ . That will make that possible.
I've been using the JAD Eclipse plugin to reverse engineer jar libraries on the fly.
http://jadclipse.sourceforge.net/wiki/index.php/Main_Page
However, it is worth to note that the decompiled source code does not exactly match the line numbers in stack traces.

Java SxS (side by side) configuration

I am facing a very obscure issue, while I am trying to run a java app in Windows, Side by Side (SxS).
I have done all the preparation creating the java.exe.config and java.exe.manifest files, which I have in the same folder with the JRE.
The application runs normally when I invoke it from the command line (by starting a .bat file). The .bat file uses the SxS configured Java (which is the only one in the box I am running the application)
However, when I try to invoke it from inside another Java process (using Runtime.getRuntime.exec()) or ProcessBuilder it seems that it totally ignores the SxS configuration and the child Java process is complaining it cannot find the COM libraries, which were the reason I had to do SxS. I have to add that the parent Java process is also launched by the Java.exe that is configured for SxS. Thus, I would assume that the "Runtime.getRuntime(), ProcessBuilder()" would give me the Java SxS loaded environment.
Doing some further debugging using some windows tools (procexp.exe, procmon.exe) i found out the following: When i start the application from the .bat file the .manifest file is normally read by crss.exe (as it supposed to be). However, when another process is spawned by Java the .manifest file is NOT taken into consideration at all. One possible problem i could think of is that the current directory of the Java.exe which starts the process is not the same as the java.exe.manifest file is located.
The only thing i can think of is a bug/problem (or maybe they call it a feature) in the java launcher.
Does anyone had a similar problem? Could anyone shed any light on the above? Much appreciated.
So far i had tried the following:
Run the java process from inside a .bat file. WORKED
Invoked the java process from a parent Java process using Runtime.getRuntime().exec(). DID NOT WORK
Invoked the .bat file from a parent Java process using Runtime.getRuntime().exec(). DID NOT WORK
Used ProcessBuilder setting the current directory where the .manifest file is. DID NOT WORK
I tested it in my computer and it works. Try:
read getErrorStream() from Runtime.getRuntime().exec(...); and send here, if you can't solve this,
run process with full path (C:\Program...),
compile java program to .jar, put in to folder with .bat, open CMD, set current directory to this folder and run jar file (using java -jar filename.jar),

How to create an executable (a file that starts the program on double-click like an .exe) in JAVA with Eclipse?

I've created a program in java and now I want to create an executable from it.
I'm new to java, I don't know if it should be a .exe.
I'we exported my project to a .jar file, but when I double-click it it opens "open with" window.
I want to export my project to a file that runs my program on double-click.
Is there any solution?
Export --> Java --> Runnable Jar file --> Specify the class with static main method to run.
Double click on the Jar file to run..
Thanks...
Java compiliation creates byte code for the JVM, so a native, binary executable is not created during compiliation (like C or C++ programs). This is a feature of Java.
To deploy an application to multiple systems they must have the JRE. These .jar files can be launched from the command line (see this: http://download.oracle.com/javase/tutorial/deployment/jar/run.html)
Some vendors get around this with batch files that launch the JRE to run their application's JAR (and then put these in the start menu, desktop, etc with a fancy icon).
If you want people to install your app (especially from a web page or over a network) you probably want a Java Web Start package (see this for crating one in Eclipse: http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fjava_web_start.htm)
If you just want it to be runnable on your computer, you can use the open with dialog to open it with javaw.exe in JDK_DIRECTORY\bin. Alternatively, if you really wanted to make it an EXE, you could look at some of the answers here.
Either do as in the link mentioned by #dacwe or I would suggest to depending on operating system set a permanent connection between java and jars, then it will always happen.
On Windows you do it by right clicking on any jar then open with and find your javaw.exe in bin folder of your jre installation.
I think you are looking for a simpler approach than Java Web Start.
I assume that you are a Windows User, since you want a .exe file.
So once you have the exported MyProgram.jar file, you only need to create a .bat file
that contains a sole line:
java -jar MyProgram.jar
and place this execute.bat file in the same folder as your MyProgram.jar
This approach works for Linux too, only you need to place it inside a similar file and execute the same command.
Read here http://javabeanz.wordpress.com/2009/01/29/running-an-executable-jar-from-command-line/ for more explanations.

Do I need a Mac to make a Java application bundle?

I want to create a Java application bundle for Mac without using Mac.
According to Java Deployment Options for Mac OS X, I can do this by using Xcode, Jar Bundler, or from the command line. Once the files and folders are set up, all I need for the command line method is to call /Developer/Tools/SetFile. Is there a SetFile clone on Linux or Windows? If not, do I have to get a Mac?
A Java application bundle on OS X is nothing more than a directory containing your .jars and a number of configuration files. The SetFile tool sets a custom HFS filesystem property on the directory to tell finder that it is an app, but giving it a ".app" extension serves the same purpose. I don't think there's anything stopping you from building one on, say, Windows, though of course you have no way of testing that it works, but if you are able to test it at least once on a real Mac, you could then conceivably update the .jars within it on Windows to reflect code changes without too much difficulty.
Have a look at the Bundle Programming Guide for more info.
One way is to generate a zip file with the App using for example Ant. In ant you can specify that the file in Contents/MacOS should have execute-permissions using something like filemode="755".
Technically, you don't need a Mac. Applications in OS X just require a specific folder structure and an XML file. However, the Mac has a really nice tool called Jar Bundler. In addition to setting up the bundle directories and XML file, it creates a C executable that launches your java application via JNI. This is nice because the process name matches the application name.
I believe that you could have someone generate an application bundle for you once, and then check in the files to your project. At build time, all you would need to do is copy your jar files to the appropriate locations and maybe update the XML file.
Having worked on the Mac port of NITE, I can say that jar packages for other platforms should work equally well on Mac. I would still recommend finding a mac for testing (or even announcing mac support was in beta) as we discovered a few mac-only quirks during the port (to go with the windows- and linux- only quirks we'd already discovered)

Categories

Resources