0

I have this netbeans project structure:

/my_project
|__/controllers
|   |__/factories
|      |__Factory.java
|   |__/integrator
|      |__Integrator.java
|
|__/models
|   |_Models.java
|
|__/main
    |_Main.java   

But, how can I compile/run it from command line?

This post works for me to compile, but not for run it.

There is a way to run it without using tools like Ant?

Community
  • 1
  • 1
auraham
  • 1,679
  • 2
  • 20
  • 27
  • Netbeans use Ant scripts to perform most of its compilation work (maven projects are an obvious exception). If you still ave the build.xml (nbproject folder), you can use Ant to build the project fom the command line. We se this very technique to build our companies application – MadProgrammer Sep 22 '12 at 22:48

1 Answers1

2

If you do not use any external jar you can easily write an OS script (sh or bat) which calls javac for all those .java files and then (another one which) calls java on the .classfile containg the void main(String[] args) method and sets the classpath.

If you want to use other libraries (provided in jar files) and you want to keep your script the same; you can copy them at this location: JAVA_HOME/lib/ext, where JAVA_HOME is the environment variable pointing to where the JVM (jre) is installed

Random42
  • 8,989
  • 6
  • 55
  • 86
  • If i decide to write an script as you say, how can I set the classpath? – auraham Sep 22 '12 at 22:52
  • @auraham You call `java` with `-cp` or `-classpath` command line argument followed by the path to the `.class` you want to run: `java -cp /where_is_stored_on_disk/my_project main.Main` – Random42 Sep 23 '12 at 08:23