(Steps to upload a project to Maven Central)
Reason” With drive, and some further instruction, a person can move what one has in Java code to the OSSRH central repositories, or the system of internet links that makes project setup easy for others. Once another person have “Apache Maven” installed, he only needs a “group identifier” and “artifact identifier” pasted into a file, and that file can be read to download and manage your entire project on their computers via the use of command line commands. Sounds cool. If only there weren’t so many steps…
So that I don’t forget, I will write these down.
Before we get there, we need to set up these big projects, so that others can access them. We have just one repository. It has to fit a lot of minor projects in them, and these projects may need to communicate with each other at some point.
I will talk about the steps I would take to make big multi-module Maven projects, after I made it happen the first time in August 2021. The end goal is to build a set of Spring projects linked together by Maven POM files declaring these projects. I want to be able to share the code between the projects. We’re using Eclipse 2020-09 for this tutorial. We’re going to assume that the correct Java JDK useful for compiling the code has been downloaded and installed to your machine. By the end of all this tutorial, we will have a multi-module Maven project ready to be customized for serving a Java Spring Web Page.
- Create a brand-new Workspace
The first step is to start fresh with a new workspace where a project’s information will go. Name it after the java version of all projects to be initialized within.
Create a new folder on your hard disk. It need not be completely empty, but it cannot already have a workspace data folder (such as .metadata) inside of it.
Now put the specific workspace for your project inside this folder (call it multimod-mavenspace) for instance.
Open eclipse.exe and type the location of that folder into the Eclipse workspace launcher.
Step 2. Create a folder and start and complete Eclipse New Maven Project Wizard
Inside this workspace, create a new maven project at a location called <project_loc>, a folder with no content inside where you can freely place and manage your code via the Eclipse IDE. Later in your eclipse project you will add in XML elements and attributes (called “maven coordinates”) similar to these shown in the Figure below. I want to build a web application written using Java server code, so my coordinates will take on the idea of describing such an application.
We wish to create this file in the Figure.
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.jsaddlercs.multimodproject</groupId>
<artifactId>multimodproject</artifactId>
<packaging>pom</packaging>
<name>multimodproject</name>
<description>Multi Module Project for Java Server App</description>
</project>
We wish to create this file, but to do so we’ll need to navigate the Eclipse GUI.
- In the file menu at the top left of the Eclipse window, Open up [File] > [New] > [Project].
- Under the “Select a Wizard” window, click the “Maven” Dropdown, then click
[Maven Project] - Eclipse has a “Create a simple project” checkbox option that will be useful to us. Ensure it is checked
- Ensure “use Default workspace location” is unchecked, and In the “Location:” field, choose <project_loc> as a location. Make sure you place the exact full pathname of the folder you want your pom.xml file and the rest of your work for this tutorial to land.
- Click <Next>
You should now be in the Wizard window entitled: “New Maven Project”
- Now
These coordinates will help us down the road. the stems of artifactId, groupId, are going to become of major use to us. Note we choose artifactId and the ending stem of groupid to be the same. For now this is my policy, but it is not required.
Model Version: 4.0.0
groupId: com.jsaddlercs.multimodproject
artifactId: multimodproject
name: multimodproject
description: Multi Module Project for Java Server App
Note that the packaging is set to “pom” in the figure (can be done after the wizard is closed). This is also very important. This project we are dealing with now is a project without code, but that allows us to add code later that will be important.
Remember, the goal is to have:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.jsaddlercs.multimodproject</groupId>
<artifactId>multimodproject</artifactId>
<packaging>pom</packaging>
<name>multimodproject</name>
<description>Multi Module Project for Java Server App</description>
</project>
- This is also an acceptable way of declaring the project element at the top. Eclipse can use this namespace information to help ensure correctness in named POM elements you define later.
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
3. Maven requires that we add pieces and bits to the XML files in our project, to make coding and setup a lot easier. Next time.