gtmsingh
gtmsingh

Reputation: 106

How to compile and run a Netbeans java project in command line without jar file?

I have a java Netbeans project having directory structure:

EMailQueue/
|-build/
|-classes/
|-mailqueue/
|-nbproject/
|-src/
 |-mailqueue/
|-dist/
 |-lib/
|-build.xml
|-maifest.mf

build/classes/mailqueue/ directory consists of all the classes compiled from all the .java files in src/mailqueue/ directory and dist/lib/ consists of all the .jar files (except JDK) imported in the application's files.

I want to know, how to run this application without using the jar file present inside the dist/ directory.

Also I want to know if I do not have classes files with me then how to compile .java files in src/mailqueue/ to generate class files in build/classes/mailqueue/ directory.

PS: Please give the exact command to run in terminal and optionally any explanation.

Upvotes: 2

Views: 4453

Answers (1)

Maks
Maks

Reputation: 368

To compile Netbeans project You need to call Apache ant tool and pass them your build script file thorough -f parameter like this

ant -f ../apppath/build.xml

this will do full project with building jar file. If You look at build.xml file You will see that it's only points to ./nbproject/build-impl.xml file where all required actions are actually defined. Once no parameters passed to ant it calls default target

<target depends="test,jar,javadoc" description="Build and test whole project." name="default"/>

You see that this task depends of three other. Most interest is 'jar' target.

Look at this target - it depends of other 'compile' target

To call this target directly You need to pass this target to ant tool

ant -f ../apppath/build.xml compile

This will compile project but not to pack them to jar

ant -f ../apppath/build.xml run

will compile project and run main class

Hope this helps.

To compile Your code with pure java You need at first to run java compler in folder with all java files i.e call javac. javac -cp {path to all java library files and external class files} *.java Once You have all compiled with no errors run java same way and pass them Your main class name You want to run java -cp {path to all java library files and external class files} ClassName

Upvotes: 4

Related Questions