打包与部署
选的sentiment-1.0.0.RELEASE.jar,大小114M,rz,命令上传到服务器之后
java -jar sentiment-1.0.0.RELEASE.jar
,后台运行是nohup java -jar sentiment-1.0.0.RELEASE.jar >sentimentBEspring.txt &
nohup java -jar sentiment-1.0.1.jar >sentimentBEspring1.0.1.txt &
clean+install的一篇博客https://blog.csdn.net/weixin_44433499/article/details/104859323
报错
无论哪种方法,java -jar sentiment-1.0.0.RELEASE.jar
时都报错:
Exception in thread "main" java.lang.IllegalStateException: Failed to get nested archive for entry BOOT-INF/lib/spring-boot-starter-data-elasticsearch-2.3.2.RELEASE.jar
at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchive(JarFileArchive.java:103)
at org.springframework.boot.loader.archive.JarFileArchive$NestedArchiveIterator.adapt(JarFileArchive.java:236)
at org.springframework.boot.loader.archive.JarFileArchive$NestedArchiveIterator.adapt(JarFileArchive.java:227)
at org.springframework.boot.loader.archive.JarFileArchive$AbstractIterator.next(JarFileArchive.java:188)
at org.springframework.boot.loader.ExecutableArchiveLauncher.createClassLoader(ExecutableArchiveLauncher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:55)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
Caused by: java.io.IOException: Unable to open nested jar file 'BOOT-INF/lib/spring-boot-starter-data-elasticsearch-2.3.2.RELEASE.jar'
at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:304)
at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:290)
at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchive(JarFileArchive.java:99)
... 6 more
Caused by: java.lang.IllegalStateException: Unable to open nested entry 'BOOT-INF/lib/spring-boot-starter-data-elasticsearch-2.3.2.RELEASE.jar'. It has been compressed and nested jar files must be stored without compression. Please check the mechanism used to create your executable jar file
at org.springframework.boot.loader.jar.JarFile.createJarFileFromFileEntry(JarFile.java:331)
at org.springframework.boot.loader.jar.JarFile.createJarFileFromEntry(JarFile.java:312)
at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:301)
... 8 more
参考https://www.icode9.com/content-4-587428.html将pom.xml的下方plugin注释掉了之后重新打包,则运行成功
<!-- for com.chamc.sentiment.util shade https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.x/java-rest-low-usage-shading.html
In order to avoid version conflicts, the dependencies can be shaded and packaged within the client in a single JAR file (sometimes called an "uber JAR" or "fat JAR").
Shading a dependency consists of taking its content (resources files and Java class files) and renaming some of its packages before putting them in the same JAR file as the low-level Java REST client.
Shading a JAR can be accomplished by 3rd-party plugins for Gradle and Maven.
Be advised that shading a JAR also has implications.
Shading the Commons Logging layer, for instance, means that 3rd-party logging backends need to be shaded as well.
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>org.apache.http</pattern>
<shadedPattern>hidden.org.apache.http</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.logging</pattern>
<shadedPattern>hidden.org.apache.logging</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.commons.codec</pattern>
<shadedPattern>hidden.org.apache.commons.codec</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.commons.logging</pattern>
<shadedPattern>hidden.org.apache.commons.logging</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>