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
Related
If you have a small program, you can run jar file and it will work fine. But if you convert jar file into exe, you still need java to run your exe file, so what's the difference between them and why do some people convert jar to exe?
An EXE is, ostensibly, an executable program that launches the local java to execute the bundle classes.
As you may know, on your computer you can associate certain file extensions with local programs. For example, .doc files with your word processor.
Similarly, .jar files can be associated with Java, so that Java can execute them. The jar file is considered "stand alone" if it has all of the necessary classes bundled within it, and a proper manifest pointing to the startup class.
So, by associating .jar with Java, clicking on it in your environment will launch Java with the given jar file.
An EXE doesn't need that association. It find java on its own with it's own launcher.
The next step is that you can actually bundle the JRE in to an EXE, so you don't even need to have the user install Java as a pre-requisite. But that's a different process.
People commonly use Java executable wrappers for two reasons - 1. to simply deployment for environments without a JVM, and 2. To make sure the exact Java runtime used for developing the application gets used to run the JAR. However, the practice is not that much widespread.
Java archive or jar is an archive of compiled java byte code and resources which can be run on a java virtual machine. ".exe" is a windows extension for directly executable code mostly used by installers or programs that do not need to be installed. I think your "people" are talking about installers.
An Exe file is an executable file that can be executed in Microsoft OS environment.
Jar file is container of Java Class files, including other resources related to the project. Jar file can be executed only if Java run time environment.
The JavaTM Archive (JAR) file format enables you to bundle multiple files into a single archive file.
The .class files compiled from java files, can not be launched directly. That is why it is needed to be converted to exe before it can run in a windows environment.The usual way to start a java program by batch file is not a convenient way. So inorder to avoid this difficulty we need to convert jar files into exe file.
Also converting it to exe. enables the program to run by simple double click on the program, instead of having to compile it with an IDE or through the JVM.
All that the exe will do is to start a jvm with your app, something like this: "java -jar app.jar".
Assuming that I use NetBeans 7.3 , I created a project that, in a nutshell, receiving as input a set of parameters, it returns as output a print on screen. The project is made up of a number of directories. Each directory contains a class (in file.class form). One of these directory contains an executable in C. I wrote it as the kernel of the Java project.
I built file.jar and I added it as a library in a new project. When I tried to test it, an error message made me realize that the C written program is not was automatically added to file.jar under construction.
One of my first attempt to solve this problem was to manually add the C-executable file. By using the JAR command from the terminal on my Mac, I was able to update the file.jar adding the executable in the right subfolder.
This solution is not served because, moving from project to file.jar, the relative path that leads to the execution of the C-program has changed. So I tried to change this path seeing it from the point of view of file.jar. Yet this attempt was futile.
I defer to those with more experience than me in the packaging and distribution of Java content.
As far as I know, an operating system cannot directly execute an executable that is inside a zip file (which is what a jar file actually is). It has to be first extracted.
So your program could first open its own jar file and extract the executable file into a file on disk, then run that file.
You can create an installer program, to install both the jar file and the executable file to a suitable location on the user's disk.
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?
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
I have written a java program that is actually works as a gui to an existing command line program.
so in basic all my program does is Runtime.getRuntime().exec("myprogram parameter");. So I have exported my java source as a executable-jar file by using Eclipse IDE and it is working nice, however I indeed need to include this myprogram.exe to the directory of the generated jar file inorder to work.
Now I am looking for a way to include myprogram.exe inside the jar file so I can keep it bundled as a single file, a method using using Eclipse would be preferred.
You can simply jar it up as an extra resource (like a .css, .properties etc.).
When your Java program runs, extract the .exe using Class.getResourceAsStream() and write it to a temporary directory in order to run it from there (since you can't run it directly from the .jar file).