【個人springboot項目】打包部署

1.jdk不說了,網上一大堆

2.mysql安裝稍微說一下

wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

yum -y install mysql57-community-release-el7-10.noarch.rpm

yum -y install mysql-community-server

systemctl start  mysqld.service

systemctl status mysqld.service
看到正在running即可

grep "password" /var/log/mysqld.log
可以看到密碼

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';

yum -y remove mysql57-community-release-el7-10.noarch
這個把它卸載掉


GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';

flush privileges;

如果還是無法連接,檢查是否防火牆屏蔽了mysql端口的遠程訪問權限。但是,我部署雲服務器不打算這麼做

不想把mysql允許遠程訪問,防火牆不想關。

 

注意mysql建庫:

CREATE DATABASE IF NOT EXISTS yourdbname DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

 

3.打包

idea 設置 

進入project Structure( 快捷鍵 Ctrl+Shift+Alt+S或者File->Project Structure ),選中‘Artifacts’,點擊中間的綠色+號(Project Settings->Artifacts->JAR->From modules with dependencies )

 

4.centos

yum install lrzsz

上傳jar直接啓動   java -jar XXX.jar

報錯信息

no main manifest attribute, in x.jar

 

 

使用命令

java -cp official.jar com.zhongjian.official.OfficialApplication
 

也會報錯

java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.
	at org.springframework.util.Assert.notEmpty(Assert.java:464)
	at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getCandidateConfigurations(AutoConfigurationImportSelector.java:183)
	at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getAutoConfigurationEntry(AutoConfigurationImportSelector.java:119)
	at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector$AutoConfigurationGroup.process(AutoConfigurationImportSelector.java:420)
	at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGrouping.getImports(ConfigurationClassParser.java:878)
	at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.processGroupImports(ConfigurationClassParser.java:804)
	at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorHandler.process(ConfigurationClassParser.java:774)
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:185)
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:315)
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:232)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95)
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:705)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
	at com.zhongjian.official.OfficialApplication.main(OfficialApplication.java:15)

參數不對,說明這樣恐怕不行的。

java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.

改一下maven幫我打包呢,但是:

Plugin 'org.springframework.boot:spring-boot-maven-plugin:' not found

然後就看下這個了

 

1,如果你的POM是繼承spring-boot-starter-parent的話,只需要下面的指定就行。

<properties>
    <!-- The main class to start by executing java -jar -->
    <start-class>com.mycorp.starter.HelloWorldApplication</start-class>
</properties>

2,如果你的POM不是繼承spring-boot-starter-parent的話,需要下面的指定。

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <version>1.3.5.RELEASE</version>
  <configuration>
    <mainClass>${start-class}</mainClass>
    <layout>ZIP</layout>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>repackage</goal>
      </goals>
    </execution>
  </executions>
</plugin>

好了,這裏pom不報錯了

 

但是打包依舊報錯:

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test (default-test) on project official: There are test failures.

Please refer to E:\project\official\target\surefire-reports for the individual test results.
Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.

 

pom跳過即可

            <!--添加配置跳過測試-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>

 

 

但是來了新的問題了,我的項目,打包不打我要執行的類了。

如果spring-boot-maven-plugin報錯,是需要添加版本號的情況的。

 

 

 

可以了,已經啓動了

 

 

 

最後一步,記得nohup一下。

nohup java -jar official-0.0.1-SNAPSHOT.jar >/dev/null 2>&1 &

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章