how to add address of input file when creating jar file? [duplicate] - java

This question already has answers here:
How do I create an .exe for a Java program? [duplicate]
(7 answers)
Closed 9 years ago.
I have created a project in java Netbeans and I want to create an .exe or .jar file that can be run on any other systems.
my project have a Main.java class and an other class GetRules.java .
the .exe file should be such that it can be run in any folder that contain train.txt as input and create Model.txt as output
how can I do this?

what you are looking for is an executable file which can execute you project
calling you main class
so here is what you can do
step 1 : collect all the files , class files
step 2 : create a jar file collecting all the files from your project
step 3 : this.jar file is executable on any environment with a JVM available
you will have .jar file , rather than .exe file , but serves you the purpose
you can refer this link to learn how to create jar files

Java programs are not compiled into exe files but Java byte code which is usually stored in jar containers. exe files run on Windows systems only, but Java byte code is platform independent.
What you could do is use a wrapper like Launch4j. It wraps the jar file into an exe file.

Related

Are jar files decompressed on the fly [duplicate]

This question already has answers here:
How does a jar file get executed? Do the classes get extracted somewhere?
(2 answers)
Closed 3 years ago.
Take a standalone executable jar file for example, in which we generate from our application with all the dependencies etc. My understanding is that this file contains all the classes etc. compressed.
When we execute this jar file via the command line as follows java -jar myjar.jar , is this being decompressed on the fly? Does the interpreter first decompress everything before executing or how does this work exactly?
We already have one answer to similar question here :
How does a jar file get executed? Do the classes get extracted somewhere?
The JVM is capable of loading classes or files from a jar file without extracting the jar to temp files.This functionality is also available to you in the standard library, see the JarFile for more information.
So no, the JVM does not extract a jar to temp files, classes (and resources) are simply loaded on demand.
We can also check if the jar gets extracted or not by executing the command "java -jar myjar.jar" and check the folder where jar is located if there is any extraction while executing the program.

How to run java class from a war file deployed in tomcat server? [duplicate]

This question already has answers here:
JAR vs WAR file specification
(4 answers)
Closed 5 years ago.
I have web application inside it I have a timer in a main method I wont to lunch the timer from a command line when I did this command :
java -classpath mywar.war my.packege.myclass
I got main class not found
That won't work. The class files are in a different place in a WAR file compared to a JAR file. You can't use the two interchangeably. You'll need to repackage your code as a JAR file.
Better still, package your code as a JAR in a separate 'project' and then place the JAR in WEB-INF/lib in the WAR file. i.e. treat the JAR file as a dependency.

How to finalize a java program, should it be in an .exe file? [duplicate]

This question already has answers here:
How to make Java program installable?
(6 answers)
Closed 9 years ago.
I made some programs in java but I don't know what I should do afterwards finalizing it for the end user. all I have is a bunch of .class and .java files in a directory and I have no idea how to distribute it to the user. Isn't java supposed to work like a normal program where I install it through a self-extracting file or InstallShield like how pc games install their programs? Thank you.
I've read on deployment but mostly I saw was how to package it into a .jar file. I'm not sure how that works but the user would most likely not be able to know what to do with a package file unless I include detailed instructions on how to operate it. I was hoping there would be a way that I install the entire java program with a .exe file like a normal program does and it will load up into a specified directory and create start menu/desktop shortcuts for the user to use.
Thank you in advance.
.jar Files are runnable on each Plattform. That's the advantage of java. So you can roll out the .jar or you can run it into an Java-applet. Or you build an .exe launcher...
Like this:
https://stackoverflow.com/a/15409917/2617699
Export it into an executable jar using eclipse. The you can create an exe using Launch4j or any similar software.

how to compile a jar file in source code [duplicate]

This question already has answers here:
How do I create a ZIP file in Java?
(2 answers)
Closed 9 years ago.
Is it possible to compile class file to jar file not using jar -cvf options.
I want to compile jar files by source code.
Cant somebody show me some example codes
A JAR simply is a ZIP file.
While I am not quite what you are trying to achieve, I can give you these hints:
Compiling: javac Hello.java
Creating a JAR: zip Hello.jar Hello.class
If you want to have a JAR containing your sources, you could as well run the above command with: zip Hello.jar Hello.java
Also note that, if you are using a build tool like for example maven, there are various plugins for suchs tasks such as 'assembly' (for maven).

Turning Java code into a program? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to make executable program in java?
I would like to know how I can open my GUI program without going through the terminal? It being independent, and simply having to click on an icon and it open it.
You need to build a jar file, you can do this with the following command
jar cf jar-file input-file(s)
The options and arguments used in this command are:
The c option indicates that you want to create a JAR file.
The f option indicates that you want the output to go to a file rather than to stdout.
jar-file is the name that you want the resulting JAR file to have. You can use any filename for a JAR file. By convention, JAR filenames are given a .jar extension, though this is not required.
The input-file(s) argument is a space-separated list of one or more files that you want to include in your JAR file.
The input-file(s) argument can contain the wildcard * symbol. If any of the "input-files" are directories, the contents of those directories are added to the JAR archive recursively.
http://docs.oracle.com/javase/tutorial/deployment/jar/build.html
I think you're looking for a jar file. See the Creating a JAR file Java tutorial.

Categories