Izpack executable jar to RPM - java

I'm trying to create a rpm package for an executable jar generated using izpack. It's basically an installer wizard that allows a user to install a tool/software. It provides an executable jar. So we have to do
Java -jar file.jar
To initialize the wizard. I'm trying to automate it in Linux by creating an rpm that takes this jar and an sh file that executes this jar and runs the sh file when I execute the rpm file. I'm new to rpmbuild and all the tutorials online are about copying a particular jar from the rpm file to a target location not about how to execute it.
Can someone provide me a sample spec file which does the following
Creates an rpm file with .jar and .sh
When rpm -i file.rpm is executed, it runs the .sh file which in turn executes the jar and opens the wizard.
I'm open to any other suggestions on how to make jar auto execute. I'm basically trying to create an exe similar file for linux
Thanks in advance.

I highly recommend not doing this for various reasons, because it is the exact opposite of what RPMs are supposed to do. You should instead do the installation process on a build machine (as a non-root user!) and then capture the files to be installed.
Why is your approach a bad idea?
Installation script is hidden from the user (they cannot just query the RPM scriptlet to see what changes, beyond files, you made to their system)
The final installed files won't be controlled in any way, e.g. you won't be able to verify if they had been corrupted (rpm -V) or query what package installed them (rpm -q --whatprovides /path/to/file)
"Removing" or "Upgrading" the package won't actually do anything unless you write detailed scripts to handle all these unknown files
All the other reasons I didn't list as why you use a package manager instead of blindly distributing tarball distributions like we did in the dark ages
That said, if you insist on breaking things, your solution is to put the java installation call in %post, which will execute after the files have been installed. It will call it again when you upgrade the package, so the other installer needs to handle that. But again, this is not the right approach.

Related

jpackage install to directory with read/write/excecute access on linux?

On windows, you can achieve this by using --win-per-user-install and the msi installer installs to directories like %LOCAL_APP_DATA%/<app-name>. This directory has read write access for other programs by default. I want to use the equivalent for linux. So what is the equivalent for %LOCAL_APP_DATA%/ for linux, having read write permissions by default, and how do I tell jpackage to make the installer install there?
I am packaging a jar file which manages the update of the application's files and installs them from the server. All this is done in the same directory where it is installed. I cannot change the code in this jar file, so any java code solutions can't be done. I need to achieve this using jpackage.

Completing My Project

I have finished writing a project in the IntelliJ IDEA using Java. I can not figure out how to get the project from a saved file in the IDEA to an executable on my computer (I am on Windows 10 if that matters). Then, I want to be able to put the executable on my Girlfriend's computer (mac) because it's a gift for our anniversary. She's not very tech-savvy (apparently neither am I...) so I want to be able to just drag and drop something onto her desktop and have her be able to double click it and have it work without having to install anything to her computer. (I was looking at Jar files, but something I read said that mac's do not run Jar files unless I install some things).
So what I'm really asking is:
1)Using IntelliJ, how do I finalize my project (make a JAR file)? I have been unable to find directions for this that have actually worked.
2)What file do I need to make a batch file call to get it to run my program once it is a JAR? Does it just call the JAR as a whole, or a specific .class? (Someone suggested a bash file, but I have not heard of this before, so I am open to other suggestions besides batch files. I am currently looking into what bash files are)
3)Can I make the batch file call the file indicated in question 2 via relative path, thus allowing me to keep it in the JAR or in a folder with the JAR and making a shortcut to it on a desktop (for example)?
Building a JAR in IntelliJ
Option 1 - Long way round, getting IntelliJ to build your JAR
Hit Ctrl+Shift+Alt+S to open your Project Structure settings menu.
Go to Artifacts
Click the green +
Select JAR > Empty.
Name your JAR, for example Gift
Right click on all the files in the Available Elements that you want to put into your JAR (often everything) and select Put into Output Root
Click Apply. Click OK.
Go to Build > Build Artifacts... > Build.
You'll find your JAR in out/artifacts/{JAR_NAME}/{JAR_NAME}.jar
Option 2 - Short way (Maven only)
If you're using a dependency manager like Maven and you've adhered to the Maven project structure, just use the command:
> mvn clean package
and you'll find your JAR in your target/ directory.
In either option, you may have to define your .class file that contains your main() method.
Running a JAR
The normal way to run a JAR file would be to go into cmd (Windows) or a terminal (Mac & Linux) and use the command:
> java -jar {JAR_NAME}.jar {args}
where {JAR_NAME} is the file name of your JAR and {args} are any arguments that need to be defined up front.
If you want to not use a command line you could write a script that runs the JAR for you. Then you can double-click/run the script and it runs the JAR for you.
For Windows
I'd recommend writing a simple .bat or "batch" script that will run the file for you.
Keep the batch script in the same directory as your JAR file and just have it contain:
java -jar ./{JAR_NAME}.jar {args}
You could use a Powershell script or something similar though.
For Mac/Linux
As Mac (and Linux) are Unix systems we can use a .sh or "bash" script to run the JAR. Again keep the bash script in the same directory as your JAR file and use:
#!/bin/bash
java -jar ./{JAR_NAME}.jar {args}
.bat script is exclusive to Windows systems, .sh scripts are exclusive to Unix systems.
Because Windows and Unix are two very different systems, you're not going to find an executable file that works for all systems.
Converting your JAR into an executable
You could convert your JAR into a standard Mac "app" application bundle by following some instructions here.
However, I wouldn't recommend this as it isn't really necessary when you have a simple script/command option and for this method, you'd most likely need access to a MacOS machine with development tools.

run java console program in unix

I have some code in Java using Eclipse and I would like to deploy it to unix envirnment. The program is simple console program that just takes some arguments at the run time, read a file and print out some results.
My question that what is best approach to deploy and run it in unix envirnment. I was just thinking to copy all the classes file to the unix envirnment and create a batch file to run the main class file. Does this sound okay? Or, should I create a runnable jar file?
Also, where should i put the jar files that the prgram is referencing (in classpath)?
Thanks
I think an executable jar file will solve your purpose here.
You should be able to execute it as
java -jar <jarfilename> <arguement1> <arguement2> .... <arguementN>
You can execute the jar file from the current directory itself, just make sure your jar file has executable permissions.
chmod +x <jarfilename>
ls -la
Designing for easy deployment is important in my opinion.
In our case, there are some components:
store project in the source code management system (git). we break down source code as
the developing source code to dev branch
the stable source code to release branch
use build tool, such as ant or maven, and provide a deploy script in the project. (we will talk deploy script in 3.).
provide deploy script to:
fetch the latest stable source code in the build server
build to executable files in the build server (whatever you do)
send the package to the target server
launcher (close the old app and run the new app) in the target server (via remote ssh command)
Currently, you think how to package the java, but it is a simple thing just about building and runing. When you talk about deployment, make it as easy as possible. Each time we deploy just to invoke the release script.
PS. I don't like the executable jar. Using un-packaging jars and compiled class can be sending by rsync very efficiently.
It sounds Ok and will work for you. Just one fix: you are going to write shell script for unix, not batch file.
But you can do better. Typically java classes are packaged into jar file. Jar file is just a zip file with optional META-INF, directory, MANIFEST.MF and other stuff. So it is better to package your application into jar and then run it as: java -cp yourjar.jar YourMainClass.
To create jar file you can use any tool that can create zip or utility jar that is a part of your JDK. You can also create automatic build using ant, maven, gradle, bildr etc that will help you to package your application.
I would do the following:
create a dedicated directory for this program. Copy the dependent .jar files to that directory
write a (short) script that sets the classpath to point to these jars and then executes the main class
Given the above, it's largely a matter of style as to whether you create a runnable .jar or not. It'll be hidden from the user.
I'm suggesting a script because:
you can set regularly used JVM parameters easily (memory options etc.)
it's a pain (and hardly intuitive) to type java -jar {pathtojar} etc.
By copying the jars to a dedicated directory, you can then use different versions of jars for different scripts (e.g. you may have 2 programs that use two different versions of commons-lang)
You should also (probably) use this script to explicitly determine which version of Java you use to run the program with. As you install/upgrade you don't want to break your programs and the scripts can be configured to explicitly tie down this info.
I find this quickest of all:
First, create a jar, copy to unix server and change file permission just as dopplesoldner mentioned below.
You can put your library classes and or jar dependencies in a lib folder
Then execute the jar
java -Djava.ext.dirs=lib/ -classpath yourJar.jar com.yourPackage.yourClass
yourClass will be the class having main(String args[]) method you wanted to execute.

Executable JAR on Ubuntu (NetBeans)

I'm writing a simple Swing application in NetBeans and doing so on an Ubuntu machine for the first time.
As many of you know, NetBeans automatically creates executable JARs for projects that are "set as main".
On Windows, you can double-click an executable JAR and it automatically invokes the JRE and runs the app. In Ubuntu, double-clicking the .jar file causes the file to be opened in the archive manager instead. In order to run my JAR, I either have to right-click it and select "Open with OpenJDK Java 6 Runtime" or launch it from the command line.
From the command line I get no problems whatsoever. However, when I try launching it from the right-click menu, I get an error that reads:
The file MySwingApp.jar is not marked as executable...
So I have 2 questions:
What do I have to do to set it as executable? Is this something I can do inside NB or do I have to use the shell? If I have to set permissions via the shell, doesn't that conflict with NB's policy of auto-generating **executable** JARS? And what command would I use to flip the executable bit anyhow?!?!
Is this just a Linux hiccup? I want to send this JAR to friend who run Windows and I'd like for them to be able to just double-click it and have the program launch
Thanks for any helpful suggestions!
You will need to manually tweak your build process to get the jar file marked as executable in Netbeans. Go to your project root and open build.xml. The header has instructions on adding to the build process. There is a target, "-post-jar", that is called after the jar is built. You'll need to make that target and use Ant's chmod task to modify your jar. Once you do that it will occur every time you make a jar file in that project.
It will run fine on your friend's Windows machine, as long as he has a JRE installed.
Here is a thread about running jars using double click in Linux.
You can Java like a native binary on Ubuntu (and other linuxes), it's a feature of the kernel. You need to install the binfmt-support package to give the kernel the hooks to run java in this way.
In Ubuntu open up a terminal and run:
sudo apt-get install binfmt-support
Then make your JAR file executable
chmod a+x yourjar.jar
Then you can run your JAR like any other binary by typing
yourjar.jar
Jar-files aren't first class executables, and they don't become magically executables by changing their executable flag.
If you execute a jar, you run the command
java -jar YOURJAR.jar ...
It's the same, as if you double click a png file, and expect it to run in a painting program
gimp YOUR.png
You don't need to make your png an executable one, and it will not solve a problem.
Instead, you have to tell your desktop environment, what to do when double clicking a jar or png-File, and you have to do it on Linux the same way you do it in Windows - maybe the installer on Windows does it for you, because there is normally just on Desktop Environment (Windows) on the OS (Windows), but Linux has Gnome, KDE, XFCE, LXDE, fluxbox and millions more.
And it isn't so sure what you want to do with it. Since jar-files are a special form of packed zipfiles, usually containing a Manifest and the classes, the Archivmanager isn't a false solution, and it is saver to show the content of the archive, than executing it.
Copying the file to windows has no effect. Windows not even has an executable flag, but you shouldn't fiddle with it though. You change your desktop settings, and those can't be moved to windows, and you will not want to.
And if you have the correct settings in your DE, you don't need to tell Netbeans or any other IDE repeatedly, what to do with jar-files.
I gone through Internet and I came across one article with complete steps to run jar file
http://mlartist.blogspot.in/2012/07/deployment-netbeans-project-in-linux.html
Jar files are basically a zip file, to create an executable, you have several different methods. The Best (in my opinion) is to use ant to create it. Or you can simply echo "Main-Class: YOUR.MAIN.CLASS" >> Manifest and then create your jar by jar -cmf Manifest JARFILENAME.jar INPUTFILES then, to make it executable under linux, right click on it and click on properties. Then click on permission tab and check execute. or you can be a terminal bamf and cd to the jar directory and chmod +x JARFILE.jar
HAPPY NIXING!!

jar to exe convert problem

hi i converted my jar file into an exe using jsmooth but when i install it, it shows an error like java not found.
Please help me, how can I add the jre to my exe wrapper so this problem is solved.
It is trying to get the java installation to run your application, where it might be searching in JAVA_HOME, So if the JAVA_HOME is not set in the machine where you installing your application then try to install the java and set the JAVA_HOME as a pre-requisite of your installation.
I don't believe JSmooth can actually bundle a JRE with the exe. What you can do is tell JSmooth where to expect the JRE when running the exe (as in the same folder the exe is run from). If you do this you simply need to zip the exe and a JRE up, and distribute that.
The end user would unzip this, and the resulting folder would contain your exe and the JRE. Since JSmooth knows where to look relative your exe, it can find the JRE.
i have use it using launch4j
follow the following steps
1-create project directory called e.g:project
2-copy the runnable jar file to it
3-copy the jre directory to it u can rename it or keep name as it e.g i will call myjre
run launch4j program :
1- fill the basic tap with required information .
2- go to JRE tap there is a field called (bundle JRE path ) write "myjre" add min Jar virsion 1,6 it will case you an error if you do not fill this fields
and then click run button to generate exe file , you have to remember to keep the myjre directory with along side with executable exe file
e.g the application directory should contains :
1- [you app name].exe
2-myjre
in this description you can run your application with no care if jre is installed in a machine or not and become portable
Good Luck , feel free to contact me for more details

Categories