简体   繁体   中英

Compiling a Net beans created project in Linux terminal

I created project in netbeans. In Netbeans it compiles. But i need to know the way of compiling the project in Linux. It simply not just a file. I have folder which contains Build,nbproject,src and etc.

Please tell me the way of compiling a project created in netbeans in linux terminal.

In the most basic case you compile all.java files in the src folder. This generates.class files. You then execute the main class file (which contains a main method). Don't forget to also put all other dependent classes on the classpath.

Compile:

$ cd <yourproject>/src

$ javac $(find. -name "*.java")

Run:

java -cp./ yourpackagename.YourMainClass

the -cp argument specifies the classpath. All the classes on this path will be considered as dependecies. In this case we put the classpath to ./ which is the current directory ( src ). That means if MainClass uses other classes in your project, they will be linked (made usable). If you do not specify a classpath your whole application would need to be contained in your MainClass, which is basically never the case.


Another way - much more common - you create a jar archive (basically a zip file) which contains your compiled classes. I'm pretty sure you can generate jar files within NetBeans. That generated jar file can then be executed:

$ java -jar myjarfile.jar

Most people do not directly use the IDE in order to generate the jar but rather use build tools such as Gradle or Maven.

Another option is using the jar command:

Hope this helps.

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