How is the Java project structured (compared to the Visual Studio C # project)?

I am trying to learn project automation, and I use the Pragmatic Project Automation book as a guide. These are Java examples, so it’s easier for me to follow it in Java. I have no experience using Java or any of its IDEs. However, I learned some C # using Visual Studio (although I'm still a beginner).

I'm having trouble understanding some of the components of a Java project. I am using Netbeans IDE 7.0 on Windows 7. With Visual Studio, I have a solution with projects below. With Netbeans, do I seem to have a project with directories defining the rest of the structure (and to some extent an IDE)? The equivalent of Add Reference is supposed to be adding a source to the Classpath . There is also a degree of separation between the compiler and the IDE. I am currently in a situation where I can compile my project as accurately as possible, while the IDE tells me that I still have errors (and I assume that this is due to incorrect project setup).

I am mainly looking for analogies that will help me better understand the structure of a Java project.

+4
source share
3 answers

Many similarities between the two languages ​​and the IDE. I spent many years in both. For starters, the equivalent of “add a link” in VS adds a library or jar to netbeans. In terms of reference, the jar is almost the same as the module or .dll in VS. The combination is compilation. To add a link, just go to the project menu and then properties, then to the libraries menu, from there you can add either pre-built netbeans libraries, which are collections of .jar, or one .jar, or even a project. After adding the links, you can import them into your class, just like in C #.

Netbeans doesn't really have a “solution” like VS does. You are dealing with individual projects. However, it does have the ability to add a project as a link, so you don’t need to constantly rebuild the links when you change something between several projects. He also has project groups to group similar projects.

Finally, Apache ANT is responsible for binding everything together in the background. Netbeans creates a build.xml file and build-impl.xml in the background to tell ANT how to build the project in .jar.

There are other things that I can touch on, but I think that answers most of your questions. Does it help?

+3
source

I can’t speak for NetBeans, since I use Eclipse, but you are on the right path, since the classpath is approximately equivalent to the links in the Visual Studio world. Libraries (usually .jar files) are placed in the classpath and should be there both at compile time and at runtime (you specify the path to the compiler at compile time and in the JVM at run time). The class path can contain many different entries, and they can be anywhere in the project structure (or outside of the whole).

Java itself does not impose many restrictions on the structure of your project, although various IDEs and build tools do. The only thing that is a universal limitation in all Java environments is that the source files (and class files) are placed in a directory with a name after the package name. Therefore, if your package name is com.test.something, your source files will be in SRC_DIR / com / test / something, and your class files in OUT_DIR / com / test / something (note: SRC_DIR and OUT_DIR are not special variables; each IDE will have another way to specify these directories).

Java libraires tend to greatly increase each other, so at some point you will find that there are too many entries in the classpath for manual control. Before you get there, you'll want to take a look at Apache Maven or Apache Ivy , which are dependency management tools. You need to understand how they work (as one, not both), and how to integrate them with your IDE. If you use Eclipse and Maven, m2eclipse offers a fairly complete integration between the IDE and the dependency management tool.

+1
source

With Netbeans, do I seem to have a project listing directories for the rest of the structure (and the IDE to some extent)?

Visual Studio dictates the specific layout of the project, and since the compiler is so tightly integrated into the IDE, there is no real concept of a script assembly. On the contrary, Java does not have such a structure (although certain "best practices" have appeared, such as the presence of the "src" directory for source files, "lib" for libraries, "test" for a test source, etc.) And a build script is usually required tell the compiler that he must find the source files and libraries, which artifacts to produce, as well as the assembly of other tasks (running tests, deploying, creating code metrics, etc.).

In simple cases, the IDE will take care of this for you (if you follow the convention for that particular development environment), but in the end you will probably want to take a look at the build tool to understand what happens behind the scenes. Apache Ant and Apache Maven are both outstanding offers. Ant is very flexible, while Maven is trying to dictate the overall layout. I suggest you study and see what suits.

There is also a degree of separation between the compiler and the IDE. I'm in a situation where I can compile my project just fine, while the IDE tells me that I still have errors

If your code compiles, it is correct. The IDE just acts as a consultant (and will highlight problems besides compiler errors, for example, to warn you about possible code errors or bad practice).

and I guess this is because I have a project installed incorrectly

This is an opportunity, although, as stated above, there are many other explanations.

+1
source

All Articles