因为springboot打包jar包执行jsp和在linux永久执行java -jar以及springboot的多环境配置 都是springboot的 就放在一起说了  

先说 打包jar 不能找到jsp问题:

打包成jar的时候会找不到jsp文件  只需要 在pom.xml文件添加

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<configuration>
					<encoding>UTF-8</encoding>
					<useDefaultDelimiters>true</useDefaultDelimiters>
				</configuration>
			</plugin>
		</plugins>
		<resources>
			<resource>
				<directory>src/main/resources</directory>
				<filtering>true</filtering>
			</resource>
			<resource>
				<directory>src/main/webapp</directory>
				 <!--注意此次必须要放在此目录下才能被访问到 -->
		         <targetPath>META-INF/resources</targetPath>
		         <includes>
		            <include>**/**</include>
		         </includes>
			</resource>
		</resources>
		<testResources>
			<testResource>
				<directory>src/test/resources</directory>
				<filtering>true</filtering>
			</testResource>
		</testResources>
	</build>


然后打包使用命令  mvn package

然后启动jar  使用 java -jar app.jar      

在此也说一下spring 的多环境配置:

pom.xml文件添加:

	<profiles>
		<profile>
			<id>dev</id>
			<properties>
				<profiles.active>dev</profiles.active>
				<maven.test.skip>true</maven.test.skip>
				<scope.jar>compile</scope.jar>
			</properties>
			<activation>
				<activeByDefault>true</activeByDefault>
			</activation>
		</profile>
		<profile>
			<id>test</id>
			<properties>
				<profiles.active>test</profiles.active>
				<maven.test.skip>true</maven.test.skip>
				<scope.jar>provided</scope.jar>
			</properties>
		</profile>
		<profile>
			<id>prod</id>
			<properties>
				<profiles.active>prod</profiles.active>
				<maven.test.skip>true</maven.test.skip>
				<scope.jar>provided</scope.jar>
			</properties>
		</profile>
	</profiles>


然后就可以把springboot的配置文件分成 开发用 测试用 生产环境用的xml或yml

在打包时候 使用  java -jar app.jar --spring.profiles.active=dev  这样就能指定开发环境springboot的配置文件


如果在liunx上启动jar包 使用传统的java -jar会导致 操作之后就会关闭这个程序 

所以可以使用:nohup java -jar app.jar --spring.profiles.active=dev & 来启动这个程序  当然要关闭这个启动程序 需查看端口号 

使用:ps aux|grep java 来查看java运行的端口 最后使用 kill 1020来杀掉这个端口  这里的 1020 是一个比如的端口号

因为比较急,写的可能有些粗糙 如果有问题 可以留言,一起讨论。

Logo

更多推荐