In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "how to compile and run an Eclipse Java project from a Linux terminal". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to compile and run an Eclipse Java project from a Linux terminal.
Command line used
Basically all you need is the following two commands. The-cp parameter entry is used to configure the classpath, which points to the class and jar files used. If you use multiple libraries, then each should be included in it to "." Separate.
Javac-cp "all jar file's path" package/target.java
Java-cp "all jar file's path" package.target
An Example Eclipse Project an example of an Eclipse project
Below, I create a new Java project in eclipse. The project contains a class Test in package1. Test uses third-party libraries under / lib/.
First, cd to the / src/directory folder, and then use the following command to compile the project.
Javac-cp "/ home/pc/workspace/TerminalEclipse/lib/commons-io-2.4.jar:
/ home/pc/workspace/TerminalEclipse/lib/commons-lang-2.5.jar "
Package1/Test.java
Second, run the project using the following command.
Java-cp ".: / home/xiaoran/workspace/TerminalEclipse/lib/commons-io-2.4.jar:
/ home/xiaoran/workspace/TerminalEclipse/lib/commons-lang-2.5.jar "
Package1.Test
Note: the * * part of the path is., which points to the current path.
The compilation process produces .class files under the / src/directory folder. You may want to delete them when you use eclipse again.
Potential problem
If you are developing a large-scale project, you may use a lot of third-party libraries. You can use the following code to generate the path string.
Publicstaticvoid printAllJars () {
String str = "/ home/pc/workspace/TerminalEclipse/lib"
File = newFile (str)
StringBuilder sb = new StringBuilder ()
File [] arr = file.listFiles ()
For (File f: arr) {
If (f.getName () .endsWith (".jar")) {
Sb.append (f.getAbsolutePath () + ":")
}
}
String s = sb.toString ()
S = s.substring (0, s.length ()-1)
System.out.println (s)
}
At this point, I believe you have a deeper understanding of "how to compile and run an Eclipse Java project from a Linux terminal". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.