Wrap the application to create sh file in Ubuntu Linux - java

I have created one java application which takes number of external jar files and also VM arguments passed to it.
I want to create .sh file for that application so that I cat run it on any linux system.
Please suggest me any tool to create .sh file in linux and which will also takes care about the arguments which has to be pass to application to run it.
I have use the tool named JarSplice but its not working as there is problem in loading libraries after creation of sh file .
So please suggest any tool for that.

If you're using maven to build your application there is a plugin called appassembler-maven-plugin that can create a .sh file for your application.
The groupId is org.codehaus.mojo.

You need to generate an executable jar, then you can simply run "java -jar main.jar" from there.
There are many questions on stackoverflow on how to create executable jars (you need ot set stuff in the MANIFEST.MF file in the jar file), for instance:
How do I create executable Java program?

Related

How to create .exe wrapper to install the Java application

Can any one please suggest me that how can I create .exe wrapper to install my Java application.
Currently Iam using the following command to install my application.
"java -jar application.jar"
After googling I came to know that we can create .exe by using some third party tool which is open source.
But don't know exactly which is best for my requirement. I have only application.jar with me as an input.
Thanks In Advance.
In order to make the command double-clickable, you have two options.
The first is a bat file with exactly that string "java -jar application.jar" in it, which is double-clickable just like exe.
The second is to make an exe by compiling the following C program.
int main(){
system("java -jar application.jar");
}
I like to use 7zsd.sfx to create installers for my java applications.
Directions:
1.) install 7zsd.sfx from http://7zsfx.info/en/ and install 7z
2.) create a .7z archive
3.) add all the jre files required to run the java application to the archive
4.) add the application itself to the archive
5.) add a .bat or .exe file (for windows) to install the files after 7zsd.sfx extracts all the files
6.) add a .bat or .exe file to run the java application using the jre files
7.) create a file (preferably named "app.tag") with a structure such as that below (add your own parameters)
;!#Install#!UTF-8!
Title="My App"
BeginPrompt="Do you want to install My App?"
Progress="yes"
ExtractDialogText="Please wait while app files are being extracted..."
GUIFlags="32"
ExtractTitle="Installation"
FinishMessage="My app has been installed and added to your desktop."
RunProgram="setup.bat"
;!#InstallEnd#!
The RunProgram is the program that runs after the files are extracted to a temporary folder. This program should create a permanent folder to hold the necessary extracted files (jre, java application, and executable to run app with jre). Additionally, the program should create a nice, good-looking shortcut for the executable file used to run the app and it should move it to the desktop and add an icon.
Finally, to create the exe which will install your files, go to the command line and access the folder with 7zsd.sfx and type in the following command:
copy /b 7zSD.sfx + [pathToDirectory]\app.tag + [pathToDirectory]\yourAppArchive.7z [pathToDirectory]myExeInstaller.exe

Compile and export in java via Terminal

I have a Java program in Eclipse on Mac currently, and I normally have to use multiple clicks just to export my code into a .jar file to test on my server. I would like to automate the process via terminal.
Basically, I compile my code usually by selecting the project
Export as Runnable JAR file
Select library handling: extract required libarires into generated JAR
Select export destination and hit done.
How can I do this via terminal? I assume this would first require me to compile the Java file, then to convert it to jar is a whole another step.
Help would be much appreciated.
You can create shell script that does it. This technique is obsolete since ~1998. So, use one of popular build tools. If you are starting now take a look on Gradle. Although there are a lot of other tools: good old ant, maven, buildr, ivy etc.
You can script all these activities using a build script. Several libraries exist for this, but Apache Ant is a good place to start. Ant build scripts can be run from command line or within eclipse, and will do all compilation, packaging and (some) deployment for you with a single command.
http://ant.apache.org/
Create default entry point manifest file as in : http://docs.oracle.com/javase/tutorial/deployment/jar/appman.html
Open Terminal and create an executable jar file like this:
Sample Script:
#!/bin/bash
# set CLASSPATH if needed
cd workspace/src
javac -d . *.java
jar tf exported.jar .

How to run Java applications without using an IDE or the command prompt

This is more curiosity than a problem:
I was recently wondering if there was a way to run compiled Java applications without using the cmd or an IDE such as Eclipse. I use Eclipse, but it isn't very useful if you want to run the program independently. Can you save Java files in Windows Explorer so you can create a shortcut for them? If so, how? Is there some sort of special extension to the file? I've heard of .JAR files, but I'm not sure what they are. Can anyone tell me how to do it?
.JAR files are archives containing - amongst other things - your compiled classes and a manifest file. You may set the main entry point of your application in that manifest. See Setting an Application's Entry Point.
Normally if you double click a jar file in windows it will be opened by javaw.exe -jar <yourFile.jar>. javaw.exe will lookup the manifest and try start the main class defined there.
create the jar file for java application using following syntax jar -cvf .jar . then use javaw.exe -jar

Creating a jar file to be run on any other machine

I have to create a jar file wherein i need to add external jar files in the classpath, properties files, in such away as to run it on any other machine.
You could either use manifest.mf to define external class path or use script that composes classpath and runs your application.
I really recommend you to use a build tool such as Maven for these things:
http://maven.apache.org/
How can I create an executable JAR with dependencies using Maven?
Regards,
Boskop
You can make the jar in almost any IDE. I agree with Michael SchmeiBer, be a bit more specific please.
I use eclipse as my IDE (because you can both use it in windows and Ubuntu Linux) to make a jar (you can define the startup class in the jar).
I use different methods for starting up of different machines.
I use nsis to create a nice windows executable (.exe) You can include your own icon.
In nsis script you actually use the same command you would use in a batch command.
nsis has some nice features, like search for a java jre.
For Linux and Mac I use a .sh file with this command.

Running a Java Program (which uses HDFS JAVA API) outside $HADOOP_HOME

I have a simple Java program which simply reads and writes some text to a file on HDFS. I run it using hadoop HDFSReadWrite text.
I want to run it from eclipse or just like any other java program and still be able to use the HDFS outside the Hadoop environment. Is there a way to do that? I need it real bad.
I was able to run a mapreduce job in Eclipse. It's shouldn't be much different from a HDFS program.
Start the namenode and the datanode from the command prompt.
Create a Java Project in Eclipse.
Include the common, hdfs and the required jar files.
Include the HDFSReadWrite.java file in the project.
Pass the following parameters to the java program.
"-- config ConfigurationDirectory text"
Execute the HDFSReadWrite
Instead of including the jar files the corresponding Eclipse projects can be included in the build path or the src jar files attached for debugging purpose.
Instead of a creating a Java project, copy the hadoop-eclipse-plugin-*.jar file in the eclipse plugin folder and create a 'Map/Reduce Project'. Then the required jar files are included automatically.
The different command options are mentioned in the below URL
http://hadoop.apache.org/common/docs/r0.21.0/commands_manual.html

Categories

Resources