我总是使用spring-boot创建uber jar并使用java -jar springboot.jar
命令启动容器。现在我的要求发生了变化,我需要指向外部类路径,如下所示,这是不固定的。我仍然为春季靴子制作超级罐子。
java -Dprofile=dev -cp springboot.jar:/usr/local/hadoop/lib/*:/usr/local/hbase/lib/* com.myapp.Application
它抛出以下内容:
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/scheduling/annotation/AsyncConfigurer
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
Caused by: java.lang.ClassNotFoundException: org.springframework.scheduling.annotation.AsyncConfigurer
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 13 more
我的Application类使用org.springframework.scheduling.annotation.AsyncConfigurer
这里的主人:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludeGroupIds>org.apache.hadoop,org.apache.hbase</excludeGroupIds>
<excludeArtifactIds>hadoop-yarn-common,hadoop-yarn-client,hadoop-annotations,hadoop-yarn-api,hadoop-mapreduce-client-jobclient,
hadoop-mapreduce-client-shuffle,hadoop-mapreduce-client-app,hadoop-mapreduce-client-core,hadoop-mapreduce-client-common,
hadoop-yarn-server-common,hadoop-hdfs,hadoop-auth,hadoop-common,parquet-hadoop,hadoop-client</excludeArtifactIds>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.myApp.Application</mainClass>
</manifest>
<manifestEntries>
<Build-Scm-Branch>${scmBranch}</Build-Scm-Branch>
<Build-Revision-Number>${buildNumber}</Build-Revision-Number>
<Timestamp>${timestamp}</Timestamp>
</manifestEntries>
</archive>
</configuration>
</plugin>
有一件事我注意到spring-boot-maven-plugin将所有超级jar保存在lib文件夹中,而不是提取每个类,将它放在像shamp插件这样的平面层次结构中。我不知道是不是因为-cp没有识别任何超级课程?
由于
答案 0 :(得分:1)
如果通过为spring-boot-maven-plugin设置<layout>ZIP</laout>
来使用PropertiesLauncher,则可以使用loader.path属性扩展类路径。 E.g:
java -Dprofile=dev -Dloader.path=springboot.jar,/usr/local/hadoop/lib,/usr/local/hbase/lib -jar springboot.jar