运行jar文件时弹出启动时出现java.lang.ClassNotFoundException - 添加了库

时间:2017-01-15 02:44:23

标签: maven spring-boot fuzzy-logic

我正在将jfuzzylite-5.0.1.jar库导入我的spring启动项目。我的库是用这种方式导入的:

<dependency>
    <groupId>com.fuzzylite</groupId>
    <artifactId>jfuzzylite</artifactId>
    <version>5.0.1</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/libs/jfuzzylite-5.0.1.jar</systemPath>
</dependency>

当我使用库在我的项目中编写单个类时,它可以工作。我在我的控制器中使用它。

构建项目时,不会发生错误,BUILD SUCCESS。

但是在tomcat服务器或excute jar文件上部署时,会发生以下错误:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.4.3.RELEASE)

2017-01-15 09:33:03.431  INFO 6944 --- [           main] com.fuzzy.FuzzyTcmApplication            : Starting FuzzyTcmApplication v0.1 on DESKTOP-8L48946 with PID 6944 (C:\DATA\DATA\G
IT_PROJECTS\fuzzy-tcm\Sourcode\fuzzy-tcm-back-end\target\fuzzy-tcm-0.1.jar started by PC in C:\DATA\DATA\GIT_PROJECTS\fuzzy-tcm\Sourcode\fuzzy-tcm-back-end\target)
2017-01-15 09:33:03.440  INFO 6944 --- [           main] com.fuzzy.FuzzyTcmApplication            : No active profile set, falling back to default profiles: default
2017-01-15 09:33:03.642  INFO 6944 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebAp
plicationContext@5b37e0d2: startup date [Sun Jan 15 09:33:03 ICT 2017]; root of context hierarchy
2017-01-15 09:33:06.439  INFO 6944 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-01-15 09:33:06.465  INFO 6944 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2017-01-15 09:33:06.468  INFO 6944 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.6
2017-01-15 09:33:06.635  INFO 6944 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2017-01-15 09:33:06.636  INFO 6944 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3029 ms
2017-01-15 09:33:06.898  INFO 6944 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2017-01-15 09:33:06.912  INFO 6944 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-01-15 09:33:06.913  INFO 6944 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-01-15 09:33:06.913  INFO 6944 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-01-15 09:33:06.913  INFO 6944 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2017-01-15 09:33:06.977  WARN 6944 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fuzzyServices': Failed to introspect bean class [com.fuzzy.controller.FuzzyServices] for looku
p method metadata: could not find class that it depends on; nested exception is java.lang.NoClassDefFoundError: com/fuzzylite/term/Term
2017-01-15 09:33:06.984  INFO 6944 --- [           main] o.apache.catalina.core.StandardService   : Stopping service Tomcat
2017-01-15 09:33:07.013  INFO 6944 --- [           main] utoConfigurationReportLoggingInitializer :

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-01-15 09:33:07.028 ERROR 6944 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fuzzyServices': Failed to introspect bean class [com.fuzzy.controller.FuzzyServices] for looku
p method metadata: could not find class that it depends on; nested exception is java.lang.NoClassDefFoundError: com/fuzzylite/term/Term
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:269) ~[spring-be
ans-4.3.5.RELEASE.jar!/:4.3.5.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1079) ~[sp
ring-beans-4.3.5.RELEASE.jar!/:4.3.5.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1052) ~[spring-beans-4.3.5.RELEASE.
jar!/:4.3.5.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.5.RELEASE.jar!/:4
.3.5.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.5.RELEASE.jar!/:4.3
.5.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.5.RELEASE.jar!/:4.3.5.RELEASE]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.5.RELEASE.jar!/:4.3.5.RELEASE
]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.5.RELEASE.jar!/:4.3.5.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.5.RELEASE.jar!/:4.3.5.RELEASE]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759) ~[spring-beans-4.3.5.RELEASE.jar!/:4.3.5
.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) ~[spring-context-4.3.5.RELEASE.jar!/:4.
3.5.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.5.RELEASE.jar!/:4.3.5.RELEASE]
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.3.RELEASE.jar!/:1.4.3.RELEASE]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.3.RELEASE.jar!/:1.4.3.RELEASE]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.3.RELEASE.jar!/:1.4.3.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.3.RELEASE.jar!/:1.4.3.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.3.RELEASE.jar!/:1.4.3.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.3.RELEASE.jar!/:1.4.3.RELEASE]
        at com.fuzzy.FuzzyTcmApplication.main(FuzzyTcmApplication.java:10) [classes!/:0.1]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_101]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_101]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_101]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_101]
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [fuzzy-tcm-0.1.jar:0.1]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [fuzzy-tcm-0.1.jar:0.1]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [fuzzy-tcm-0.1.jar:0.1]
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [fuzzy-tcm-0.1.jar:0.1]
Caused by: java.lang.NoClassDefFoundError: com/fuzzylite/term/Term
        at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_101]
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source) ~[na:1.8.0_101]
        at java.lang.Class.getDeclaredMethods(Unknown Source) ~[na:1.8.0_101]
        at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:613) ~[spring-core-4.3.5.RELEASE.jar!/:4.3.5.RELEASE]
        at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:524) ~[spring-core-4.3.5.RELEASE.jar!/:4.3.5.RELEASE]
        at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:510) ~[spring-core-4.3.5.RELEASE.jar!/:4.3.5.RELEASE]
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:247) ~[spring-be
ans-4.3.5.RELEASE.jar!/:4.3.5.RELEASE]
        ... 26 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.fuzzylite.term.Term
        at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_101]
        at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_101]
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94) ~[fuzzy-tcm-0.1.jar:0.1]
        at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_101]
        ... 33 common frames omitted

我附上了jar文件,包含了库。可能是什么问题?

1 个答案:

答案 0 :(得分:2)

原因可能是明确的 -

<scope>system</scope>
  

此范围与提供的类似,但您必须提供   显式包含它的JAR。工件总是可用的   没有在存储库中查找。

如果系统中没有显式的工件JAR,则应尝试使用默认范围

<scope>compile</scope> <!-- you can avoid using scope entirely-->
  

这是默认范围,如果未指定,则使用此范围。编   依赖项在项目的所有类路径中都可用。   此外,这些依赖项将传播到依赖项目。

此外,请避免使用systemPath和使用${project.basedir}等的相对路径值,因为它们现在已在maven中弃用。

来源 - Dependency Scope in MavenAll Variables