Distributing .jar files - jar

I wanted to distribute a .jar file to a layman audience (all windows users). But I can't run the jar file myself unless I do it from cmd using "java -jar "C:\..\file.jar".
When I double click on the file nothing happens (the default program is Java Platform SE Binary). Someone suggested this site but I couldn't follow along in Win8.
So I want the user to be able to double click on the jar file and launch it directly without me telling them to open command prompt and typing stuff, or giving them the link.
PS: it is a very simple non-GUI application. Thanks for your time.

I think your best bet is to create a file.bat script that will run the jar, with this simple line in it:
java -jar file.jar
Give the users both files, file.jar and file.bat, and they can double-click on file.bat to run it.
In theory, if the jar file has a manifest in it (META-INF/MANIFEST.MF) with the main class defined in Main-Class: then it should be runnable by double-click. However, you say the app doesn't have a GUI, in which case it will run just fine, but you won't be able to see it.
In any case, the bat file should help, in the worst case users can just run that and not worry about typing java -jar ... etc.

How did you create the jar file? Jar files have a manifest file inside to, amount others, indicate the location of your main method. Check that this is correct.
You should be able to run the app by double clicking it but it can only be a program with a GUI or a program without direct user interaction.

Related

Streamlit: Disable the guard against running files without a .py extension?

I have a problem. Universally, my experience working in Unix systems has been that, by the time you are ready to place an executable "thing" in a bin folder for global access, you have decided to #! the file with the requisite interpreter:
#!/bin/awk
#!/bin/bash
#!/bin/perl
#!/bin/python3.8
#!/bin/whatever
And, although it is fine to have clutter at the local scope, when one places an executable in the bin folder, it should have:
A POSIX CLI interface
No discernible language tags or what have you
This is because it is now intended to be used for difficult work that requires forgetting about the details of this or that language: one now needs to think in terms of the functions as if the composable units are part of a consistent language, rather than a dozen different languages from a dozen different expert contributors.
This is the "genius" of the Unix/Linux/Posix architecture.
Anyways, when structuring my python projects, the end game is copying python executables to a global source on the path -- whether that "global" source is a pretend global source in my home directory (i.e., ~/.mytools/bin or the actual global path, /usr/bin or something like that -- and generally I want my python executables to have the same "game feel" as C executables, perl executables, BASH/ZSH/etc. executables.
In that vein, I knock off the extensions from my scripts and executables when they go in the bin. There is no need to know, from my usage perspective, what anything is made of when I go to use it.
However, streamlit requires me to re-append the .py to the file in the global path in order to run with streamlit run. This is a case of the library reaching up out of its useful value and holding me hostage, from my perspective, unless I violate best practices when extending the bin folder with python executables.
This means I have to create special logic to handle just streamlit, and that is really a kerfluffle. I have to either: change the way I handle all executables, or hardcode just the executable that will be run with streamlit. That means that, all of a sudden, I have an arbitrary name in my meta-control code for my project.
That is bad. Why? because I have to remember that I did it, and remember to change it if I change the executable name. I also have to remember to add to it if I add another streamlit executable.
Alternatively, I can copy all my exes made with python into the root bin folders with their .py extensions, which is not what I wanted to do.
How does one bypass this issue in streamlit?
If bin/sometool needs to be invoked with Streamlit via streamlit run bin/sometool, it seems like you're already exposing "meta-control code" to users of your bin script, right?
Instead, would this solve your problem?
bin/sometool:
#!/bin/bash
DIR=$(dirname "$0")
streamlit run "$DIR"/the_actual_script.py
(Where the_actual_script.py sits inside bin, but has chmod -x so that it's not directly executable.)

Converted UWP... Nothing Happens

I have converted a Win32 Application to UWP using MakeAppX and it doesn't seem to run. When I click the icon in the start menu literally nothing happens except a busy icon briefly appears on the cursor.
I completed the same process with Notepad++ and all it's DLLs and that worked fine (using the exact same manifest file, just changing the exe)
My questions are:
Where does the UWP save files that it creates/temporary files etc? If I run an executable and it generates files next to it, where would that be when you run a UWP?
Can I set that location in the AppxManifest?
Is there anyway to see if it has run correctly or not?
Edit:
Could this be a file permissions issue? My application needs to write to 'C:\MyFolder' & creates a folder with a load of files next to the executable upon startup and that doesn't happen.
So looking into this a bit more I came across this blog which discusses preparing for conversion. I think the above file accesses probably contravene the following:
Your app writes to the install directory for your app. For example, your app writes to a log file that you put in the same directory as your exe. This isn't supported, so you'll need to find another location, like the local app data store.
This looks like a fairly halting issue, am I correct in that assumption?
If your app is writing to the install directory you will need to change that code to write to your local app data folder instead, as the preparation guide calls out.
Write operations to the install directory are not allowed in order to ensure the ability for the app deployment stack to perform seamless, differential updates and clean uninstalls of your app.
Btw, to debug through your app launch failures you can do the following in Visual Studio: Debug -> Other Debug Target -> Debug Installed App Package -> select your app from the list of installed apps.

Identifying the jar file association on Task Manager

I have a server which runs multiple jar file at the same time as of now.
Currently we just make a bat file, call the java -jar xxxx.jar program, and the window is pop-ed up on the screen so we know which to terminate when we'd like to turn one of them off.
But as we progress we prefer those program to run at the background hence we'd prefer to use javaw -jar xxxx.jar instead.
However when we open up the task manager all it shows is many javaw.exe processes, without telling us which jar file its associated to.
Is there any parameter we can specify when we start javaw, so there's some indication on task manager's process list?
There is an official product named Process Explorer that can do what you want.

Batch: How to move a .exe from network drive to Program Files

I'm new at batch and I'm trying to make a simple script that moves an executable from a network drive to a certain folder in Program Files. The script will be executed by people who have admin on their computer. The exe cannot be execute elsewhere because it needs all necessary library files in that specific folder in Program Files(SDK limitation).
Manually, I can't directly drag the exe from the network drive into the folder because I get a warning and then an error. The warning says: "You'll need to provide administrator permission to copy this folder". I do, so I click continue. Then I get an error saying that the network drive "X:" does not exist. However, if I first copy the exe from the network drive to Downloads (local), and then cut and paste from Downloads to the folder in Program Files, I get the same warning but it moves the file after I click on continue.
Seeing how I could not manually do a straight copy over, I made a simple batch file that copies my second approach:
COPY "X:\Path\to\program.exe" "C:\Users\Me\Downloads\"
MOVE /-y "C:\Users\Me\Downloads\program.exe" "C:\Program Files\Company\SDK\"
The first line works fine. The second line returns an access denied. Seeing how I was able to access Program Files, is there a way to grant shell the same access. This batch script will be executed by people who only know the basics of computing so I was hoping the script does all the work and they just need to double click it.
You can not copy a file from network to your "Program Files"
Copy it in desktop then copy from "desktop" to "program files"

C/C++ code or Bash script to sign jar files

Is there C/C++ code or a Bash script that can sign Java .jar files without using a JVM?
Such code might be useful for embedded applications that serve a jar file with a small HTTP server, or other situations where a jar file might need to be edited and re-signed programmatically but there is insufficient storage space for a JVM.
Does anyone need this type of Javaless jarsigner?

Resources