错误: 找不到或无法加载主类 com.myali.TTSmy
问题原因: ide中编译能找到相关包,但是,打包成jar时,本地的jar引入失败
maven将系统用到的包从线上maven仓库下载到本地的maven目录;
那么我们手动将jar包按照路径格式放入maven的本地仓库目录即可
然后按照“从远程仓库的调用方式”,写入pom即可;
Java SDK_语音合成(TTS)_智能语音交互-阿里云 https://help.aliyun.com/document_detail/30431.html
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>MyGid</groupId>
<artifactId>MyAid</artifactId>
<version>1.0.0</version> <dependencies>
<!--<dependency>-->
<!--<groupId>com.alibaba.idst</groupId>-->
<!--<artifactId>nls-service-sdk</artifactId>-->
<!--<version>${project.version}</version>-->
<!--<scope>system</scope>-->
<!--<systemPath>${project.basedir}/lib/nls-service-sdk-1.0.0.jar</systemPath>-->
<!--</dependency>-->
<dependency>
<groupId>com.alibaba.idst</groupId>
<artifactId>nls</artifactId>
<version>1.0.0</version>
</dependency> <dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.26</version>
</dependency>
<!-- ============================================== -->
<!-- websocket netty 实现 -->
<!-- ============================================== -->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty</artifactId>
<version>3.7.0.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.21</version>
</dependency> <!-- https://mvnrepository.com/artifact/org.jboss/jboss-common-core -->
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-common-core</artifactId>
<version>2.5.0.Final</version>
</dependency>
</dependencies> <build>
<!--使用的插件列表-->
<plugins> <!--将依赖的资源全部打入lib目录-->
<!--<plugin>-->
<!--<groupId>org.apache.maven.plugins</groupId>-->
<!--<artifactId>maven-dependency-plugin</artifactId>-->
<!--<configuration>-->
<!--<outputDirectory>${project.build.directory}/lib</outputDirectory>-->
<!--<excludeTransitive>false</excludeTransitive>-->
<!--<stripVersion>false</stripVersion>-->
<!--</configuration>-->
<!--<executions>-->
<!--<execution>-->
<!--<id>copy-dependencies</id>-->
<!--<phase>package</phase>-->
<!--<goals>-->
<!--<goal>copy-dependencies</goal>-->
<!--</goals>-->
<!--<configuration>-->
<!--<outputDirectory>${project.build.directory}/lib</outputDirectory>-->
<!--<excludeTransitive>false</excludeTransitive>-->
<!--<stripVersion>false</stripVersion>-->
<!--</configuration>-->
<!--</execution>-->
<!--</executions>-->
<!--</plugin>--> <!--Maven引入本地依赖Jar到可执行Jar包中 | IT草根 http://www.codepub.cn/2017/06/13/Maven-introduces-local-dependency-jar-to-executable-jar-packages/-->
<!--打包插件,在Jar包中添加Class-Path和Main-Class-->
<!--<plugin>-->
<!--<groupId>org.apache.maven.plugins</groupId>-->
<!--<artifactId>maven-jar-plugin</artifactId>-->
<!--<version>3.0.2</version>-->
<!--<configuration>-->
<!--<archive>-->
<!--<!–使用自己的Manifest文件,运行正常–>-->
<!--<!–<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>–>-->
<!--<!–使用插件添加的Manifest文件,运行正常,一定要注意Manifest中jar包名称和lib文件夹下jar包名称版本号后缀等一定要一致,否则找不到依赖jar,此处有坑–>-->
<!--<manifest>-->
<!--<addClasspath>true</addClasspath>-->
<!--<!–指定依赖资源路径前缀–>-->
<!--<classpathPrefix>lib/</classpathPrefix>-->
<!--<mainClass>com.mycom.TTSmy</mainClass>-->
<!--</manifest>-->
<!--<!–可以把依赖本地系统的Jar包加入Manifest文件中–>-->
<!--<manifestEntries>-->
<!--<Class-Path>lib/nls-service-sdk-1.0.0.jar</Class-Path>-->
<!--</manifestEntries>-->
<!--</archive>-->
<!--</configuration>-->
<!--</plugin>--> <!--idea打包jar的多种方式 - byhieg - 博客园 https://www.cnblogs.com/qifengshi/p/6036870.html-->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.mycom.TTSmy</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<useUniqueVersions>false</useUniqueVersions>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.alibaba.idst.nls.producing.TTS</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
<!--Maven中使用本地JAR包 - RichardJing - 博客园 https://www.cnblogs.com/richard-jing/archive/2013/01/27/Maven_localjar.html--> <!--<dependency>-->
<!--<groupId>com.alibaba.idst</groupId>-->
<!--<artifactId>nls-service-sdk</artifactId>-->
<!--<version>${project.version}</version>-->
<!--<scope>system</scope>-->
<!--<systemPath>${project.basedir}/lib/nls-service-sdk-1.0.0.jar</systemPath>-->
<!--</dependency>--> </build>
</project>