Java SxS (side by side) configuration - java

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),

Related

launch4j-maven-plugin windows 7 file associations

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

Drag&Drop file to jar file (in Windows Explorer)

I have written a Java application, that analyzes some data from within a zip file.
I can pass the filename as command line argument to the application (java -jar myapp.jar fileToAnalyze.zip) and it does what it is supposed to do.
Unfortunately it is somehow complicated to call the application via command line. I would like to simply drag the ZIP file to the jar and let it start. I have absolutely no idea how to do this. Could you please give some hints?
Thanks in advance.
It seems that windows doesn't allow file drops on jar files. But short of finding a solution for that you could instantiate a JFrame when you run your jar file and make it listen for dropped zip files on that instead.
An example of that can be found here.
It still (10/2021) seems that Windows does not allow this.
What you can do:
create a batch file with the java call to your program. This will open a command line window along with your program and might seem ugly.
create a desktop link to your java.exe (or javaw.exe). In the properties of the link, add "-jar YourJarFile.jar" as command line arguments to the link target.
In both cases, Windows will send the dropped file to your program as command line arguments.

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.

Java create executable cmd line program(windows)

I'm new to java and have recently created a stress testing application to test server configurations. Its very simple and all is done within cmd line. I used eclipse to create the jar file and that seems to have worked fine.
The problem that I am running into is making this executable. If I use java -jar in windows cmd line to execute the program, it runs fine. However, I need to be able to run it by "double clicking" the jar file(right now I click on it and nothing happens) or create a .exe which defeats the purpose of java, but this will only be used in windows.
When I click on the jar now nothing happens, but when using the java - jar in cmd it works. Not all of the computers have java in the cmd line, but have it installed. I'm not sure why a cmd window doesnt pop when clicking on the jar?
Again I'm new and any help is much appreciated!!
Create a sortcut icon that will do java -jar yourFile.jar
In windows, you can associate the jar file with the JRE jar runner. Take a look at this post, which explains your options pretty well.
Make a bat file for Windows. You can do this by the following:
#echo off
java -jar YourJarName.jar
Save this in a text file with the .bat extension.
It should run the JAR once double clicked if the JAR file is in the same directory as the .bat file. Otherwise you will have to navigate to the JAR file relative to where the .bat file is located.
You said you didn't want an exe but not sure if this will be ok for you. It shouldn't be a problem for someone to click the .bat file first and will work in all cases under Windows.
Hope this helps.
If you want to get really awesome with it and have it show up in your Task Manager with an app.exe naming and handle any startup options, you should read into JNI. JNI will allow you to wrap the starting and stopping of a Java app using a windows executable and it is actually very simple to implement.
If you want something as simple as a windows exe launcher, there are also tools out there such as Launch4j will create exe wrappers for you.

How do i run a Java program from the command line using an Eclipse launch file?

i've been given the task of creating a ksh script which runs one Java program multiple times and another once. The idea is that the multiple runs test the ability of the single program to handle multiple threads.
The issue i am having is that i want to use a .Launch file generated by Eclipse to specify the run time dependencies of the two Java programs and i have no idea how to do this via command line in either Windows or Unix.
Can any body help me??
cheers.
To me it sounds like trying to link an IDE environment to an application running outside of the IDE is problematic, and a bit squirrly. Rather than trying to figure out how to "use" the .Launch file, roll up a jar file and run the application that way. For Eclipse, just right click the project, pick export, then navigate to a runnable jar file. It should be pretty straight forward.

Categories

Resources