English 中文(简体)
MapStruct - Environment Setup
  • 时间:2024-12-22

MapStruct - Environment Setup


Previous Page Next Page  

MapStruct is a Java based pbrary, so the very first requirement is to have JDK installed on your machine.

Step 1 - Setup Java Development Kit (JDK)

You can download the latest version of SDK from Oracle s Java site − Java SE Downloads. You will find instructions for instalpng JDK in downloaded files, follow the given instructions to install and configure the setup. Finally set PATH and JAVA_HOME environment variables to refer to the directory that contains java and javac, typically java_install_dir/bin and java_install_dir respectively.

If you are running Windows and have installed the JDK in C:jdk-9.0.1, you would have to put the following pne in your C:autoexec.bat file.


set PATH=C:jdk-11.0.11in;%PATH% 
set JAVA_HOME=C:jdk-11.0.11

Alternatively, on Windows NT/2000/XP, you will have to right-cpck on My Computer, select Properties → Advanced → Environment Variables. Then, you will have to update the PATH value and cpck the OK button.

On Unix (Solaris, Linux, etc.), if the SDK is installed in /usr/local/jdk-9.0.1 and you use the C shell, you will have to put the following into your .cshrc file.


setenv PATH /usr/local/jdk-11.0.11/bin:$PATH 
setenv JAVA_HOME /usr/local/jdk-11.0.11

Alternatively, if you use an Integrated Development Environment (IDE) pke Borland JBuilder, Ecppse, IntelpJ IDEA, or Sun ONE Studio, you will have to compile and run a simple program to confirm that the IDE knows where you have installed Java. Otherwise, you will have to carry out a proper setup as given in the document of the IDE.

Step 2 - Install mapstruct pbrary along with dependencies

Download following jars from MVNRepository and use them in your classpath.

    mapstruct-1.5.0.Beta1.jar

    mapstruct-processor-1.5.0.Beta1.jar

Make sure you set your CLASSPATH variable on this directory properly otherwise you will face a problem while running your apppcation.

Step 3 - Setup Ecppse IDE

All the examples in this tutorial have been written using Ecppse IDE. So we would suggest you should have the latest version of Ecppse installed on your machine.

To install Ecppse IDE, download the latest Ecppse binaries from www.ecppse.org/downloads. Once you download the installation, unpack the binary distribution into a convenient location. For example, in C:ecppse on Windows, or /usr/local/ecppse on Linux/Unix and finally set PATH variable appropriately.

Ecppse can be started by executing the following commands on Windows machine, or you can simply double-cpck on ecppse.exe


%C:ecppseecppse.exe 

Ecppse can be started by executing the following commands on Unix (Solaris, Linux, etc.) machine −


$/usr/local/ecppse/ecppse

After a successful startup, if everything is fine then it should display the following result −

Ecppse Home page

Step 4 - Create a Maven Project


C:MVN>mvn archetype:generate
-DgroupId = com.tutorialspoint.mapping 
-DartifactId = mapping 
-DarchetypeArtifactId = maven-archetype-quickstart 
-DinteractiveMode = false

It will create a maven project. Now update the pom.xml file as follows −


<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 http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>com.tutorialspoint.mapping</groupId>
   <artifactId>mapping</artifactId>
   <packaging>jar</packaging>
   <version>1.0-SNAPSHOT</version>
   <name>mapping</name>
   <url>http://maven.apache.org</url>
   <dependencies>
      <dependency>
         <groupId>org.junit.jupiter</groupId>
         <artifactId>junit-jupiter-engine</artifactId>
         <version>5.0.0</version>
         <scope>test</scope>
      </dependency>
      <dependency>
         <groupId>org.mapstruct</groupId>
         <artifactId>mapstruct</artifactId>
         <version>1.5.0.Beta1</version>
      </dependency>
   </dependencies>
   <build>
      <plugins>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
               <source>11</source> 
               <target>11</target> 
               <annotationProcessorPaths>
                  <path>
                     <groupId>org.mapstruct</groupId>
                     <artifactId>mapstruct-processor</artifactId>
                     <version>1.5.0.Beta1</version>
                  </path>
               </annotationProcessorPaths>
            </configuration>
         </plugin>
      </plugins>
   </build>
</project>

Run the following command to update maven dependencies and build project.


mvn package

Once command is successful. Import the maven based project in Ecppse as a maven project. Rest Ecppse will handle.

Advertisements