Reputation: 1
I am fairly new to coding, but I have been given a miniature project at my internship to help automate a process I am working on. I know of a fairly simple way to do this in Java, but the only problem is that the person who would benefit from this program does not have an IDE on their computer.
Basically, my question is how to run a program created on Eclipse on a computer that does not have an IDE (it has the latest JRE update, though). I have only really done programming in the closed box of a classroom, so I've never run into this problem and can't seem to find an answer to this online. I just need an explanation of how the program could be accessed and then used without the IDE.
Upvotes: 0
Views: 2186
Reputation: 62789
"Building" can be a pretty big question. First of all I assume you have the JDK or JRE installed and properly pathed. That's a question to look up on it's own if you don't. To get SOMETHING working, try this:
Create a java file named "MyClass.java" that looks like this:
public class MyClass
{
public static void main(String[] args)
{
System.out.println("Hello, World");
}
}
type the following in the same directory:
The first command creates a MyClass.class file from MyClass.java. The second executes MyClass.class. If this doesn't work, you may have to add "-cp ." to the java command.
This is the absolute simplest case, it gets more complicated when you add packages--you start to need multiple directories and a more realistic classpath. Hopefully after getting something working you will have a baseline you can figure out the rest from.
PS. the way did this is just for testing, you should always put your java classes in packages and never use the "Default" package like I just did--I only did it to simplify your directory layout for a first run.
Edit: Regarding pathing
Your path must contain the bin directory from your JDK. For our mini-test you could fully path javac and java (like c:\jdk\bin\javac if your jdk was in c:\ which it never is).
For an easier solution you can add it to your path or build a batch file. When I'm developing a small one-file app I usually write a little .cmd batch file or a unix shell script that does these steps:
This way, at least during development, I don't alter the system's path (batch files and shell script path changes are discarded on exit) and since I'm mostly testing, always rebuilding with javac isn't really comparatively expensive.
If you create a second batch file/script without the "javac" step it will be faster (won't compile each time) and can be used to actually "Run" your finished app.
This is the very beginning of a simplified "Build system". If you use packages, you must issue a javac command for each directory containing files (To build a whole directory at once, javac *.java should work).
In the long run this doesn't scale well and people start to use bigger build systems like Ant, Maven and Gradle (in increasing order of preference), but for tiny one-package deployments, a batch file is acceptable.
Upvotes: 1
Reputation: 2982
You need to package and share your code in a jar
file. A jar
file will run on any computer that has the JRE
installed.
For a concise information on how to do this with Eclipse, please visit: Creating and sharing a JAR
Upvotes: 1