在我完成弹簧启动服务器之后,我想把它变成一个jar,这样我就可以将它部署在远程服务器上了。我选择用maven
做这件事创建.jar-with-dependecies.jar后,我将其上传到服务器上并尝试运行
java -jar buyme-0.0.1-SNAPSHOT-jar-with-dependencies.jar
像其他人一样
Error: Could not find or load main class com.buyme.BuymeApplication
我从这里尝试了答案:
似乎没什么用。 这是我的
的pom.xml
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.buyme.BuymeApplication</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
清单
Manifest-Version: 1.0
Main-Class: com.buyme.BuymeApplication
这是项目结构
mvn命令:
mvnc clean install (sometimes i tried assembly:assembly with the other two)
这不起作用:
java -cp <name>.jar com.buyme.BuymeApplication