Provide/Export executable file to client - java

I just completed working on a client's tool, which uses Jfreechart jar, and dll and a lib file for JNI interface. Now I would like to export/ provide a executable file to client, I tried to click on java project folder and export Java>Runnable Jar file (extract required libraries into generated JAR) , a Jar file is exported with some Warnings. However, we are not able to run the file on client's machine. How can I fix this, obviously I don't want to provide complete Java project and ask client to run from and IDE. Please provide me inputs.

Since Java is a cross-platform environment, it doesn't really have "executable files" like EXEs or anything. Instead, you run your .jar file with the Java runtime. For example:
C:\>java.exe MyProgram.jar
Of course some operating systems will just do this for you once the Java runtime is installed.
There are some programs to convert .JAR to .EXE, but I believe they just compile a thin wrapper that calls into the Java runtime.

Related

How to execute .exe from within runnable jar file

I am working on a Java desktop application and want to execute an .exe file upon some user action.
I want to package the .exe inside the executable jar so that I have to ship just one item to my customer/user. But so far I have not been able to execute an .exe file which is packaged inside the jar.
One more input, the .exe in turn uses a bunch of .dll, .xml and .exe files (total 12 files), so I need to package all of them to make this work. Is this possible in java or should I use another language to achieve this?
I chose java because I want to support Mac platform also. So with these .exe and .dll files (for Win), I need to package and execute a bunch of Unix executable files and dylib files also (for Mac).
What would be the best way to achieve this?
I can think of 2 ways:
Make one Java executable app and dynamically execute exe or Unix executable file depending on platform it is running. The problem here is executing the files which are packaged within the jar.
Make separate applications for Win and Mac. In this case, which languages should I use?
Thanks much for the help!
Applications are packaged very differently on windows and mac. For the Windows version I would recommend you to distribute an installation program (see IzPack for instance) that will unpack the jar and the exe in the application directory (I don't believe you can directly execute an exe that's in a jar file). A MacOS application is actually a directory with a certain structure, so in your case, the said directory could contain both the jar and the exe.

How to use Eclipse generated .classpath file to specify the external libraries?

I need to start a Java application using a .bat file . Here is what I have so far, and it works fine
java -cp ".;C:\someLibrary.jar;C:\someLibrary.jar;..." Main
The problem is there are too many external libraries, and Eclipse already generates a .classpath file referring to all those libraries. Is there any way I could use that Eclipse generated .classpath file in my batch, so that I don't have to list all the libraries in the java command above ?
Can I use something like this
java -cp ".;C:\ ..\pathToEclipseFolder.classpath" Main
The reason I am asking this is because I will eventually end up updating some of those external libraries. And I want to still be able to use the original .bat file
If your Java application needs the libraries, then you must specify them in the classpath of your .bat file.
A couple of considerations:
1) Maybe you have more libraries listed in your Eclipse classpath than you actually need
2) Java6 and higher allows you to specify a directory, instead of requiring you to specify each individual library in that directory:
java -classpath ".;c:\mylib\*" MyApp

Java application installer for MacOS

I'm new at Java for Mac developement and I spent a lot of time finding a way how to create an installer. It's strange but it's not too much information about it. All the ways lead to using of JavaAppLauncher. (I use appbundler-1.0.jar and Ant to build .app) But I faced a following problem.
JavaAppLauncher sets working directory to user folder. My application consists of several jar files, resources and configuration files. All of them located in Contents/Java inside the .app structure. I use relative paths to them, relative to the executable jar with Main class.
I googled 2 discussions only, where someone asked how to set the working directory inside the .app bundle. Threre is a way to sed -Duser.dir JVM option in plist file of .app bundle. I tried this and it behaves strange. When I use "new File(".").getAbsolutePath()" - it shows the directory I pointed in -Duser.dir parameter, but when I try to create file on disk or read file from disk - it still goes to the user folder as it was by default.
May be someone knows what is wrong there?
Or is there any better way to create a java application bundle for Mac?
Thank you, guys.
Use JarSplice to create OS X app bundle. Compile all your jars and resources into one jar file and export as mac .app file.
Deploying Java Applications can be a pain if your application has multiple jars and native libraries. There are the options of using Java Web Start or Java Applets however these are not always suitable.
Executable Jars are an option, however if your project has multiple jars or native files then it can be tricky to use this option.
JarSplice attempts to solve this issue by allowing you to merge all your jars and native files into one, easy to use executable jar file.
Features:
Creates a single executable fat jar via an easy to use GUI.
Automatically extracts only the native files needed for the OS the jar is running on.
Automatically cleans up any extracted native files after the application quits.
Add VM arguments on jar creation which removes the need to enter them via the command line.
Optionally create a Shell Script (.sh) launcher for Linux with embedded fat jar.
Optionally create an OS X App Bundle (.app) for running your application.
Optionally create a Windows Application (*.exe) for running your application.
This is the best cross-platform installer creator i have found yet. You can get the java executable from here

Load obfuscated Java code to Eclipse failed because Windows is case-insensitive

all. I am cracking a java software, it's a jar package. I want to decompile it and load its source to Eclipse, so I can analyze it. My Environment is Windows.
I used Java Decompiler to get the source zip from the jar package. Because the jar file is obfuscated, the zip file contains many files like a.java, A.java, Km.java, km.java... in the same folder (or package in java). Zip supports case-sensitive, but Windows does not. When I load the zip to a Eclipse project, the "no-matter-case-same" files get replaced (such as A.java is replaced by a.java), because Eclipse works on the Windows file system.
I don't want to change to linux, I hope there's a Windows solution?
First, it is very, very bad to crack software. So, you are a bad guy.
Second, I'd suggest you to try to run from zip. Configure your project to be dependent on your jar file, store decompiled sources in jar file too and add this jar as a source attachment. This should work.
But better solution is just leave windows ASAP and never return to it.

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.

Categories