java.lang.ClassNotFoundException:org.springframework.boot.SpringApplication [英] java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication

查看:97
本文介绍了java.lang.ClassNotFoundException:org.springframework.boot.SpringApplication的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是该问题的后续问题:

This is a follow up question to this question:

java.lang.ClassNotFoundException:org.springframework.boot.SpringApplication Maven

我已经在Windows上使用Eclipse开发了一个Web服务.我需要在Solaris工作站上运行它,然后得到ClassNotFoundException.

I have developed a web service using Eclipse on Windows. I need to run it on a Solaris station and there I get the ClassNotFoundException.

这是我的pom.xml :(我已经读过该Maven阴影插件,它可以创建具有所有依赖项的uber jar).

This is my pom.xml: (that maven shade plugin is something I've read about that can create an uber jar with all the dependecies).

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd> 4.0.0

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>org.springframework</groupId>
<artifactId>gs-rest-service</artifactId>
<version>0.1.0</version>
<packaging>jar</packaging>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.5.RELEASE</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

<properties>
    <java.version>1.8</java.version>
</properties>


<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>

    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
              <mainClass>com.group.id.Launcher1</mainClass>
            </transformer>
          </transformers>
        </configuration>
      </execution>
    </executions>
  </plugin>
    </plugins>

</build>

<repositories>
    <repository>
        <id>spring-releases</id>
        <url>https://repo.spring.io/libs-release</url>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>spring-releases</id>
        <url>https://repo.spring.io/libs-release</url>
    </pluginRepository>
</pluginRepositories>

这是我尝试在Solaris上运行jar时遇到的异常:

And this is the exception I get when trying to run the jar on Solaris:

原因:java.lang.ClassNotFoundException:org.springframework.boot.SpringApplication 在java.net.URLClassLoader $ 1.run(URLClassLoader.java:366) 在java.net.URLClassLoader $ 1.run(URLClassLoader.java:355) 在java.security.AccessController.doPrivileged(本机方法) 在java.net.URLClassLoader.findClass(URLClassLoader.java:354) 在java.lang.ClassLoader.loadClass(ClassLoader.java:425) 在sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:308) 在java.lang.ClassLoader.loadClass(ClassLoader.java:358)

Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication 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)

该项目获得了一个"Maven Dependencies"文件夹,其中包含许多Spring框架的jar文件.

The project got a "Maven Dependencies" folder with many jar files of the Spring framwork.

我不是很了解这个问题的答案.主要答案建议创建一个合并的jar,如下所示:

I did not really understand the answers to that question. The main answer suggested creating a consolidated jar as shown here: How can I create an executable JAR with dependencies using Maven?

但是我还不完全了解如何创建这个罐子.我是否需要将答案中的行添加到pom文件中?或者别的地方?和运行mvn clean compile assembly:single应该在Windows的命令行中完成吗?如果是这样,在哪条路径上?不会只是导出到jar就足够了?

But i did not fully understand how to create that conolidated jar. Do I need to add the lines in the answer to the pom file? or somewhere else? and running the mvn clean compile assembly:single should be done in windows in the command line? and if so on which path? won't just exporting to jar suffice?

如果某人可以列出要执行的操作的列表,那就太好了.

If someone could make a list of operations of what to do, that'll be great.

推荐答案

在其他问题的答案中没有人说过,您需要使用maven创建jar,而不是使用Eclipse的导出到jar选项.您需要做的是:

What no one ever said in the answers to other questions is that you need to use maven to create the jar and not using Eclipse's export to jar option. What you need to do is:

1)从 https://maven.apache.org/download.cgi 下载maven.

1) download maven from https://maven.apache.org/download.cgi

2)Maven目录包含一个"bin"文件夹.将此文件夹添加到路径"环境变量中(在Windows 8上,右键单击此PC"->属性->高级系统设置->环境变量->在系统变量中找到路径"->双击并添加它)将bin文件夹路径添加到该变量中,就像在其上放置其他路径一样.

2) The maven dir contains a 'bin' folder. Add this folder to your "path" enviornment variable (on Windows 8 right click "This PC" -> properties -> Advanced System Settings -> Environment Variables -> in System Variables find "Path" -> double click it and add it by adding the bin folder path to that variable the same way other paths are located there.

3)打开CMD

4)导航到项目的文件夹

4) navigate to your project's folder

5)输入mvn包

jar文件是在目标"文件夹中创建的.

The jar file is created inside the "target" folder.

祝你好运

这篇关于java.lang.ClassNotFoundException:org.springframework.boot.SpringApplication的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆