0

How can I build an executable program written in java using eclipse? and there are arguments need to be passed in ubuntu terminal.

the main function is like this:

public class Sample {
    public static void main(String[] args) {...}

and I would like to call it in terminal like this:

$./program args[1] args[2]
legend0011
  • 139
  • 7

1 Answers1

0

The answers to this question give a number of options for giving a java program an executable wrapper: How can I convert my Java program to an .exe file?

That said, my preference for use on linux tends to be just bundling my compiled classes as a jar (eclipse provides an export to jar tool) and writing a shell script like:

#!/bin/bash
export CLASSPATH=`dirname $0`/my-archive.jar
java -cp $CLASSPATH my.package.Sample $@

That sets the classpath relative to the location of the script (so you can call the script from anywhere) and passes any arguments given to the script along to the java program.

Community
  • 1
  • 1
1337joe
  • 2,327
  • 1
  • 20
  • 25