In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "what is IDEA, Eclipse, Maven". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The outline of this article
Version convention
IntelliJ IDEA:2020.3.2
SpringToolSuite:4.9.0.RELEASE
Text
Next, this paper starts from the project level to explore how these problems are solved.
IntelliJ IDEA project
Come on, it's all in the first two articles in the series:
Hongmeng official Strategic Cooperation to build HarmonyOS Technology Community
I will be anxious with anyone who compares IDEA's Project to Eclipse's Workspace.
Play with IDEA project structure Project Structure, complete with Jar package, module / dependency management
Eclipse project
Since the Eclipse project has not been mentioned in this series of articles, here is a brief introduction.
To be honest, Brother A has never used native eclipse since he joined the industry in 2015, so here we take Eclipse-based STS as an example, ha, the reason is the same.
Eclipse has the concept of workspace operating space, and all Project projects are managed in the operating space. In other words, a window in Eclipse opens an entire workspace, loading as many Project as there are, so it can be done: one window opens multiple Project projects at the same time.
Create a new Project
Take a new java project named hello as an example: File-> New-> Java Project...
Contestants who are used to IDEA, when they see this page of this eclipse, do they want to sigh: it is so complicated for a project to create a page for Mao Chun? Options like JRE and working sets do not need to be selected at creation time. The page is too incompact and interferes with too much information.
Click Next:
Er, the same feeling, not to mention a novice, even the veteran saw this page also "spend more and more attractive" bar, O (∩ _ ∩) O ~. Eclipse's page design basically has this problem: too complex, too many interference options. For example, insert a class class creation page here, and you can feel it:
Click Finish,Project to create it.
Project Project Settings
Select the project with the mouse (unlike IDEA, it must be selected here), and right-click Properties to configure the project:
The number of configuration items is as numerous as cow hair, which is frightening. I won't introduce them one by one here, and graphical things are easy to understand. But do you find that the word Module is not found in many configuration items, how can you be fat?
Eclipse has no concept of Module.
What if you want to create a hello-client project under the hello project? Answer: eclipse cannot do this at the logical level, it can only be reflected under the path structure. The specific creation action is as follows: click to create a new project, then customize the path, and put it under hello.
After clicking Finish, the project structure is shown in the following figure:
The image above is Project Explorer, but if you switch to Package Explorer, the screenshot is as follows:
From this we can see that there is no logical concept of hierarchy in eclipse, and there is only Project without module.
This is true even if you are importing a maven project (maven has a module concept). Here is an example of dubbo:
Package Explorer view
So remember, this is very different from IDEA in logical structure: there is no Module in Eclipse, no Module, no Module.
Explain .classpath and .project
For each project in eclipse, there are two additional files: .classpath file and .project file. These two files are special and do not have a file name. At the beginning, it hides the file.
The students who read Brother A's last article (who compares IDEA's Project to Eclipse's Workspace) know that there are two special files workspace.xml and ${moduleName} .iml in IDEA, as well as in eclipse, which we can roughly call environment descriptors and project descriptors.
.classpath file
The .classpath file stores the Java build path for the project at compile time, which can be referenced with $CLASSPATH. This file for the hello project is as follows:
In short, .classpath defines the $CLASSPATH classpath that this project uses when compiling.
.project file
.project provides a complete description of the project, including the name, description, project type, and so on.
Explain a few labels a little bit:
Name: project name, which is usually the same as the folder name, but they are two different things
Comment: project comment
BuildCommand: the command used by the build. The value here is org.eclipse.jdt.core.javabuilder, which means that eclipse compiles it for you instead of manually typing the java command to compile it.
Natures: project type, where org.eclipse.jdt.core.javanature represents a java project
In short, .project is a project descriptor, and with this file, eclipse can follow it when it loads the project.
Explain the .settings directory
The configuration under the .settings directory of the eclipse project is relatively complex, and various suffixes may be seen, most of which are text files in the format of properties or xml. Most of the Properties type files have the suffix .prefs, while most of the XML type files have the suffixes of. * and .xml.
Because there are so many types, here are some of the more common representatives:
Org.eclipse.core.resources.prefs: specifies the encoding of the file. Try not to have multiple codes in one project.
Org.eclipse.jdt.core.prefs: specify some features of Java compilation, such as compiled version, warning level, etc.
Structural differences, IDEA and Eclipse fight?
After learning about the project structure of IDEA and Eclipse, it is found that they manage the project in a completely different way:
Hongmeng official Strategic Cooperation to build HarmonyOS Technology Community
Different logical structures
Different metadata files
The content and format of metadata files are different.
Because of these differences, there is an incompatibility problem: the IDEA project Eclipse does not recognize it, and vice versa. Although IDEA has done the function of importing Eclipse projects, the compatibility is not perfect. It is only a "stopgap measure" to "assist" Eclipse in defecting IDEA.
You might say that this has little impact, after all, it is not common for a team to use both IDEA and Eclipse. It is true that this kind of situation does not happen in general. But, why don't you enlarge your field of vision and think about it? For example, what if it is an open source project? It is for all developers to work together, you can't limit other people's IDE. Or take dubbo as an example: if you want to submit all the source code to github, should you use IDEA metadata files or Eclipse? For the project itself, the project name, structure, dependency management, etc., are stored in the metadata file.
Obviously, it is not appropriate to use anyone's. After all, the IDE of the Java platform is still a tripod (at least two feet), and it is not possible to "offend" either side. Moreover, for the program itself, IDE is not part of it, so even if IntelliJ IDEA dominates the world, you should not rely on its metadata files to help you manage dependencies and projects. Flowers don't have a hundred days red, who knows tomorrow?
Stir-frying like this will not come to a conclusion, so what to do? do we have to "do it"?
Faced with this situation, what needs to be done is standardization, so that all IDE support the identification of the same project / directory structure, and the problem is solved. At this time, there is a "person" to carry the banner, to assume this role, it is Maven (pronounced [horse mev plague], not "horse plague").
No matter what kind of IDE, you can recognize and load the maven project, parse its pom.xml file into IDEA's own metadata file, and load it normally. Therefore, for developers, you only need to manage the project for Maven, and you no longer need to care about the specific IDE, which will help you straighten out the difference. Continue to take dubbo as an example, which is exactly what it does in practice: only the source code of the maven structure and the pom.xml metadata file are submitted to github:
From then on, even if you use Eclipse and I use IDEA, you can fall in love normally.
It is worth noting that now that maven's project structure is used, some of IDE's own metadata files can no longer be submitted when submitted to github. Therefore, the following configuration items are generally added to the .gitignore file of the project:
# eclipse ignore .settings / .project .classpath # idea ignore .idea / * .ipr * .iml * .iws
Create / Import Maven Project
Now that the Maven project has become the standard, in practice, both newly created and exposed 99.99 are maven projects. Both IDEA and Eclipse provide "perfect" support for maven projects.
IDEA and Maven projects
Create a Maven project:
Selecting Maven in the left category means that you need to create a maven project, and click Next (of course, you can also select a template skeleton if the company has a unified skeleton):
Click Finish to open a new IDEA window and you are done:
Continue to create two submodules (hello-client and hello-service), also using the Maven project:
Click Finish and add Spring Context dependencies in the sub-module:
And make the hello-service module dependent on the hello-client module:
So now you can use spring-conext-related classes even in the hello-service module:
What's the reason? At this point, the content of the previous article works. Take a look at the Project Structure of the project structure to find out:
Dependency in the hello-client module: spring-context
Dependencies in the hello-service module:
There is a dependency on spring-context, so it can be used normally.
Found not, in the creation of this project, developers only need to care about the Maven way to create, module dependence when only need to change the Maven metadata file pom.xml, IDEA I will automatically "parse" to put in the project structure Project Structure and save in its own metadata file (such as xxx.iml file, etc.), so as to ensure normal operation and management.
Open / import the Maven project:
Open the window and select the pom file (or top-level folder) to get it done.
Importing the maven module is a little different, take a look at:
❝Note: there is no such thing as import import for a Project project in IDEA, because it is an independent body, which can only be said to open the project ❞.
After selecting a folder, confirm to proceed to the next step:
As shown in the figure, IDEA supports the import of many types of modules, which is powerful:
Android Gradle: for Android projects, select this option
Eclipse: if it is an Eclipse project, select this option (please note: only those who have eclipse metadata files are called eclipse projects, but it is not necessarily an eclipse project if the other party is developed with Eclipse. After all, it may still be a maven project)
Gradle project: select this item if it is a Gradle project. Like the Spring Framework project.
Maven project: 99% of the cases, we should choose this item.
Click Finish to import the module.
It is worth mentioning: many "old programmers" seem to show multiple "projects" in an IDEA window, but in fact, they import a Project as a Module module, which is very unrecommended. If you do not believe it, open your Project Structure and have a look, it is a mess, but the disaster cannot be managed. The previous articles in this series described in detail the reasons for this inadequacy and gave best practices, which you are welcome to refer to.
Eclipse and Maven projects
More or less the same, slightly.
Maven dominates the world
❝explanation: this article is not a special topic on Maven, just a few words about ❞about the current situation of its dominance.
Maven is a project management tool: it contains a project object model (POM:Project Object Model), a set of standard project structures, a project life cycle (Project Lifecycle), a dependency management system (Dependency Management System), and logic for running plug-ins (plugin) goals (goal) defined in the lifecycle phase (phase).
Every function of Maven is a killer-level existence, very powerful and easy to use, necessary for large and medium-sized projects. For example, if it depends on the management system, if it does not rely on a Jar, it has to go to the official website to down a corresponding version, then add it to the IDE and type it together when packing, which can be said to be extremely troublesome and error-prone.
I don't know when Maven already dominates the world, anyway, I know that as early as 2015, the Spring Framework team announced that its official website would no longer provide download of Jar packages; almost all popular Java projects on github are built and managed through Maven; for younger programmers, if a project is not a Maven project, they probably don't know how to get started, because the default at school is according to the maven project.
Now in 2021, the Maven project is the absolute king, the de facto standard. To put it bluntly, "almost all" large Java projects are Maven projects (Spring Boot is the Maven project by default), which is perhaps one of its greatest contributions, allowing Java developers around the world to unify the "language". The existence of Maven also greatly strengthens the Java ecology and reduces the threshold of management, construction and dependence management, so as to maintain vitality all the time.
When it comes to Maven, we have to mention Gradle. Some students may say that Gradle will replace Maven as the most popular project management build tool in the next generation. Believe it or not, Spring Framework has moved to build with Gradle. It is true that Gradle as a new generation of products has many "advantages", but in the foreseeable future, Maven in the Java platform is still the absolute standard, unshakable. After all, the function of Maven is very perfect, the key is that there are no fatal shortcomings, the motivation to change is not great. And the stock market is too large for ships to turn around or even turn around. Just like xhtml was always ambitious to kill html, in the end, you know.
❝Gradle is the mainstream in Android development, so Gradle is a good choice for this "new technology". ❞
This is the end of "what is IDEA, Eclipse, Maven". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.