Where and How to store program information in Linux - java

I'm new to Linux and I've only ever messed around with it but now I want to allow my Java program to run on Linux...
I've had a quick look around on the internet, and I've found a list of directories and their discriptions. /usr/lib seems to be the best place for me to store program information, but I've just looked in there on my VirtualBox VM and it appears that I can't write there, even with root permissions. So if anyone can point me in the right direction that would be brilliant.
I have also noticed that Linux has it's own "Software Center", and I'm afraid that I may be going to wrong way about all this, so may be some sort of introduction to programming on Linux would help if anybody would be kind enough to provide one!
Thanks In Advance
PS My Virtual Machine is an Ubuntu distribution

The file system structure of not only Linux, but any POSIX-compatible system (including BSD, Solaris, and to a lesser degree even Mac OS X) are standardized in the FHS. Specifically for Ubuntu, have a look at the Debian policy for Java and the packaging guide of the ubuntu-java team.
If your program is run interactively, it should store information(like databases and settings) in $HOME/.your-program-name (or $HOME/.config/your-program-name). If your program is a system service, it should store its information in /var/lib. You can also install a default configuration into /etc/your-program-name.
The binaries are a whole different deal, and a prefix to their location should be configurable. To get the full advantage of the Software Center and its dependency/update mechanisms, package your software. These binaries(and the libraries that go with them) will go into to /usr/ tree if packaged, and /usr/local/ if manually installed. No matter the prefix, binaries go into bin (i.e. /usr/bin), libraries into lib32/lib64, and other data into share.
If you don't want to package your program and don't want to follow the structure imposed by FHS (but you really should do that), the alternative is putting code and other objects into /opt/your-program-name. Note that the (mutable) data your program generates and operates on should still go into $HOME/.your-program-name(interactive) or /var/lib/your-program-name(service).

Store it under the home directory of the user, who is running the program - in a hidden directory (preceded with dot), for example: .program-data. The short path to it would be: ~/.program-data and a full path to it depends on the distro of the OS - usually /home/[user name]/.program-data

The simplest place to store an application is in a home directory. You may want to create a user and separate home directory for a service.
However it sounds like you are writing a command line or GUI tool in Java. A common place to store applications is under a bin directory like /usr/local/bin or /home/myuser/bin lib is usually for shared libraries loaded by applications. (Java doesn't use them)

You should always store/install applications & programs in $HOME directory.
This will allow you to easily find the applications & programs.
Make separate folders for Softwares & Programs under $HOME for easily identification.
Also, add JAVA_HOME environment variable in .bashrc file.

Related

Java installer with added libraries

I am very new to Java (first-year student). I tried searching for similar questions but can't find anything that exactly meets my needs. I am trying to figure out how to create a JRE installer for Windows that includes additional files beyond the standard libraries. In particular, I am trying to use files from this source: http://jlog.org/rxtx-win.html. I want the RXTXSerial.dll file to go into the "bin" folder, and the rxtxcomm.jar file to go into the "lib\ext" folder.
Ideally, this would be used by a user who isn't good with computers at all, so that all they would have to do is run the JRE installer, and already have the necessary RXTX files needed to run an external application (that I unfortunately don't have any control over).
Take a look at install4j...
https://www.ej-technologies.com/products/install4j/overview.html
Not sure if this is exactly what you're looking for, but you should be able to control what JRE/libs are deployed with your application using this.

using cygwin compile java file to windows native code

I have written a small java application for one of my homework. the problem is the teacher may not have JRE installed. what i want to id to compile the java file to window exe file so the teacher can run it without the JRE installed.
i use the gcj tool in the cygwin , but the output application seem to need the cygwin1.dll to run. how can i avoid this, IE package all the things the application need to a single file, so the teacher don't have to install anything.
Use MinGW instead of Cygwin.
And get ready for a 10-MiB executable.
Why don't you just ask your teacher to install a JRE, or if they have one? If you are allowed to use Java, then I'm certain the teacher will be required to have the tools for properly evaluating your homework.
If you weren't allowed to use Java, well then, what were were you thinking?
The application seem to need the cygwin1.dll to run.
Shipping an .exe with an cluster of .dll files is the norm on Windows.
If you use Microsoft Visual Studio, your program will also need be shipped with some libraries from the Visual Studio Redistributable Run-Time. (Unless you link it statically.) Most major applications on Windows have installation directories chock full of dll files, and won't run without them.
In the middle of 2016, the Cygwin project changed the licensing from GPL to LGPL. This means you can link programs with to cygwin1.dll and redistribute them, even if those programs have a license that is not compatible with the regular GPL, such as closed-source, non-freely-redistributable, proprietary programs. (If you otherwise comply with the LGPL in regard to how you are redistributing cygwin1.dll itself, of course).
IE package all the things the application need to a single file, so the teacher don't have to install anything.
The only way not to install anything is not to have a file at all. If there is a single file it has to be put somewhere, and that meets the definition of installation. On Windows, if you have a .exe file that depends on a .dll, all you have to ensure is that they are put into the same directory. This requirement can be met as easily as by putting them into a .zip file, if the program is too unimportant to warrant developing a full blown installer.
Your teacher unzips your .zip file on their Desktop, or in their Downloads directory. A folder should appear, and in that folder is your program and the dll. The program can be invoked and loads the dll; no brainer.

How should I bundle Java with my Windows application?

I have a Windows application based on Java, that I should like to install with Java bundled. The installation framework is NSIS. The application executable should be guaranteed to invoke the bundled Java, so there's no clash with other Javas installed in the system.
What's the best way to achieve my goal? I haven't tried to solve this kind of problem before, and have little experience with Java, so I don't know which solutions are out there. I think I'd prefer Java to be embedded in the application's executable, if feasible, otherwise I guess Java could be installed along with it (with the executable pointing to said Java).
Edit:
This project already generates an executable (.exe), via NSIS. The executable will by default use the system Java, but apparently it'll prefer a JRE in the same directory (i.e. bundled) if present.
Edit 2:
The scenario that made me want to bundle Java with this application was that I received an executable for it built with 32-bit Java, which failed (silently) on my system which has 64-bit Java.
Are you absolutely sure you don't want to use the computer JRE? In most cases it's preferable.
You can see here (and the included link) some examples with installers that check JRE number and install it (globally) if necessary.
If you really prefer to include your own JRE in the installer and always use it - what prevents you from doing it? It's just a matter of your main program point having some way of konwing the JRE location and forcing to use it. That depends on how you pack/invoke your Java program. Normally, it would be feasible, perhaps with a simple .bat file - perhaps to be created at installation time.
The solution we used(A few years ago, but still I think the best way).
Find a program which can generate an exe file from a jar file(Google is your friend, I can't remember the name). Note that this .exe file will still need a jre. It is just a smart way to make an exe which contain your .jar file, and which start the java process automatic. (This also allows you to set a custom icon on your .exe file).
The java sdk which you use to develop/compile your java application, also contains a folder called jre, which contain a copy of the jre.
Include this folder with the installer, so the jre folder is located in the same folder as the .exe file. Then the .exe file will use the included jre, and the jre will not be installed on the computer, so you prevent any problems.
Well one extremely simple solution that works actually quite nice if you don't have to get an executable, is just using a simple Windows Batch file that starts the jar and having a shortcut to it so you get your preferred icon on it. For the average user there's no real difference - after all the default is to suppress known extensions on Windows (horrible default but well) - and for people who do know what an exe is, the solution should be quite apparent anyways.
That way you can also easily start the included java or better yet offer both versions and just change a variable in an ini file, which really is much nicer - nobody wants or needs X different JRE versions that are outdated and are nothing more than security problems. Still can't harm to offer a version that includes the JRE for people without a java install to make it as simple as possible for them.
One example for this behavior would be weka..
launch4j seems to offer to bundle an embedded JRE.

Installing Java manually on Windows? [duplicate]

This question already has answers here:
How can I get the latest JRE / JDK as a zip file rather than EXE or MSI installer? [closed]
(30 answers)
Closed 8 years ago.
I have seen many products bundeled with JDK, I wonder if there is a way where one can install JDK by simply unzipping contents to a directory, so there is no icon created in add/remove programs, no registry entries etc.
Also in this case:
How can we configure Java plugin for browsers?
And how can we configure settings as seen via Control Panel entry for Java?
According to this, I created a batch script to build jdk archives automatically.
The essential parts of the link are:
Create working JDK directory ("C:\JDK" in this case)
Download latest version of JDK from oracle (for example "jdk-7u7-windows-i586.exe")
Download and install 7-zip (or download 7-zip portable version if you are not administrator)
With 7-zip extract all the files from "jdk-[6-7]u?-windows-i586.exe" in directory "C:\JDK"
In command shell (cmd.exe) do the following:
change directory to directory C:\JDK.rsrc\JAVA_CAB10
execute command: extrac32 111
Unpack C:\JDK.rsrc\JAVA_CAB10\tools.zip with 7-zip
In command shell (cmd.exe) do the following:
change directory to C:\JDK.rsrc\JAVA_CAB10\tools\
execute command: for /r %x in (*.pack) do .\bin\unpack200 -r "%x" "%~dx%~px%~nx.jar" (this will convert all pack files into jar)
Copy whole directory and all subdir of c:\JDK.rsrc\JAVA_CAB10\tools" where you want your JDK to be and setup manually JAVA_HOME and PATH to point to your JDK dir and its BIN subdir.
Yes, you can create a zipped up JDK, unzip it on the target machine and run java, javac, etc. from that directory to your heart's content.
The easiest way to create such a zip file is to install the JDK on a machine and then zip up the contents of the JDK directory. We do this in certain circumstances where we need to control exactly what configuration of Java will be used in our deployments. In that case, our scripts just point JAVA_HOME (or the equivalent) to our internally bundled JDK instead of relying on a sysadmin to install exactly what we need prior to arrival.
In terms of integrating with the browsers, that can be a bit more problematic. The short answer is no, you can't integrate directly with the browser without some sort of installer.
You could use SysInternals RegMon and FileMon (now owned and dist by MS) to see exactly what is modified by the Java installer. I believe there will be a number of reg entries that you will want to create. Products like WISE installer, for example, also use this sort of approach under the hood to repackage product installations (e.g. as MSI).
Please be careful since there are also some dynamic decisions made by the installer which may affect what gets installed (e.g. on XP v.s. W2K3 server). I was bitten by this once regarding installed codepages. I do not recall the precise details, but the effect was that a codepage file was missing in my embedded JRE + JDK (legally redistributable portion only). This caused a very bizarre and seemingly nonsensical runtime error in my code. It goes without saying that the same applies to Server v.s. client JVM DLLs.
Really, no, at least if you want to use it from Windows and not from, say, cygwin. Windows depends too much on the registry; you could simulate the registry updates necessary, but software that moves the files to the right place and updates the registry is called "an installer"; you'd just be reinventing the installer.
I believe this at least used to be feasible to a limited extent with earlier versions of Java - I don't know if it still is.
Most of the registry entries are used for things like browser plugins, as you mentioned in the question. If you just want to be able to run Java (e.g. from a batch file), that's one thing - but really installing it is a different matter. Even if you're just wanting to run it, you'll need to be careful to always explicitly use the one you intend, rather than using the installed one accidentally for part of your application.
What's your actual use case? Do you actually need a browser plugin? What aspect of the configuration are you interested in? A lot of the control panel configuration is to do with updates and browser integration. Many other aspects can be controlled using command line options to set specific system properties.
If you just want to provide a JVM with your application is fine, but more than that I would not recommend.
If you just want to have the JDK (JRE) files, you can run the installer within sandboxie. Once installed in the sandbox, just copy the files from c:\sandbox and you are done.
I'm using this to compile and run legacy java applications which cannot be migrated easily to a newer version of java. I can point Eclispe to this JDKs and tell it to be compliant to Java 1.3.
Just down load the Windows server version of Java from the Oracle downloads page. Setup JAVA_HOME and PATH variables on your own.

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