简体   繁体   中英

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.

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 ie 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM