xsj work notes - manually add the local jar package to the maven repository

Recently, Netease Yunxin was used to make a function to send alarm SMS under certain conditions, but after deploying to the server environment, it  appeared

java.lang.ClassNotFoundException: com.alibaba.fastjson.JSON

Motherfucker, the solution is basically: put the jar in the lib directory, and then I do the same. . still does not work;

After a thorough analysis, I tried left and right, and finally got it done: first, ensure that the lib folder in the server environment has this jar, and then manually add the jar package to the maven warehouse, and the following method is used.


1. Configure environment variables!

Because the command line must be used , before configuring the local jar, it is necessary to determine whether the maven environment variable has been configured . (Note!: Settings.xml is taken by default when executing the mvn install:installfile command, so students who usually configure settings.xml with other names in IDE should pay attention!)


2. Use the maven command to move the jar package to the local repository of maven!

pom.xml

  <build>
  <pluginManagement>
  <plugins>
	  <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-jar-plugin</artifactId>
          <configuration>
              <archive>
                  <manifest>
                      <addClasspath>true</addClasspath>
                      <classpathPrefix>lib/</classpathPrefix>
                      <mainClass>com.twpow.equipment.run.App</mainClass>
                  </manifest>
              </archive>
          </configuration>
      </plugin>
 	   <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/lib</outputDirectory>
                        <overWriteReleases>false</overWriteReleases>
                        <overWriteSnapshots>false</overWriteSnapshots>
                        <overWriteIfNewer>true</overWriteIfNewer>
                    </configuration>
                </execution>
            </executions>
        </plugin>
  </plugins>
  </pluginManagement>
 </build>

 Note: If this problem occurs, just add

 <pluginManagement></pluginManagement>, no error will be reported,

 The specific reason is unknown, it may be a problem with the m2e plugin

<dependency>
  <groupId>httpclient</groupId>
  <artifactId>httpclient</artifactId>
  <version>4.5.3</version>
</dependency>

grammar:

mvn install:install-file -Dfile=(location of jar package) -DgroupId=(groupId corresponding to dependency) -DartifactId=(artifactId corresponding to dependency) -Dversion=(version corresponding to dependency) -Dpackaging=jar

example:

mvn install:install-file -Dfile=D:\BaiduNetdiskDownload\compmany\jars\httpclient-4.5.3.jar -DgroupId=httpclient
 -DartifactId=httpclient -Dversion=4.5.3 -Dpackaging=jar

If you see the following prompt, it means the addition is successful!


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325597640&siteId=291194637