英文:
What is the command line parameter for my app?
问题
I made my first spring boot application which is working well and I want to deploy it to my VPS server yet there is a problem. I cant run it on command line interface it works fine when I double click.
Commands I have tried so far:
java -jar jarfilename.jar
mvn spring-boot:run
mvnw spring boot:run
non of them worked I would gladly add maven dependency to my pom.xlm but I right now I just want to know how I can learn what command is given when i double click.
both mvn and java commands are defined in path btw
POM file ->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>1.9.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
英文:
I made my first spring boot application which is working well and I want to deploy it to my VPS server yet there is a problem. I cant run it on command line interface it works fine when I double click.
Commands I have tried so far:
> java -jar jarfilename.jar
> mvn spring-boot:run
> mvnw spring boot:run
non of them worked I would gladly add maven dependency to my pom.xlm but I right now I just want to know how I can learn what command is given when i double click.
both mvn and java commands are defined in path btw
POM file ->
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven 4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>name</groupId>
<artifactId>test1</artifactId>
<version>1.0-SNAPSHOT</version>
<name>test1</name>
<description>My personal webpage</description>
<properties>
<java.version>14</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>1.9.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
答案1
得分: 2
你应该学习关于Spring Boot应用程序开发过程的知识 - 这将非常有帮助:
Maven是一个构建工具,用于从源文件创建应用程序的JAR文件(也称为Artifact)。Maven编译您的源代码,运行您的测试(如果有的话),然后将Artifact打包到target
文件夹中,该文件夹应在运行mvn package
命令后创建。
之后,如果pom.xml
中的定义是正确的,您将能够运行以下命令:
cd target
java -jar my-app.jar
- 在这里,
my-app.jar
是Artifact的名称,您可以在target
文件夹中找到。
请注意,特别针对Spring Boot应用程序,您应该在pom.xml
中使用spring-boot-maven-plugin
,看起来您已经正确配置了。
英文:
You should learn the about the process of development of spring boot applications - it will help a lot:
Maven is a build tool that is used to create an application’s jar (a.k.a. Artifact) from your source files. Maven compiles your sources, runs tests you have them, packages the artifact in the target
folder which should be created after you run mvn package
command.
After that, if the definitions in pom.xml
are correct, you will be able to run the following:
cd target
java -jar my-app.jar
- Here
my-app.jar
is a name of the artifact that you can find atarget
folder.
Note that specifically for spring boot applications you should use spring-boot-maven-plugin
defined in the pom.xml
which looks like you’ve done correctly
答案2
得分: 1
所以,您正在运行使用Java 8的Java 14字节码。
我认为当您双击时,系统会根据字节码版本找到合适的JVM,而当您从命令行运行时,会使用路径中的第一个JVM。
请使用此处提到的属性:https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html#
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
英文:
So, you are running java 14 bytecode with java8
I think when you double click, system finds appropriate JVM based on the bytecode version.. where when you run from command line, first JVM from path is taken.
Use properties mentioned here https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html#
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
答案3
得分: 0
If you want to take it to VPS, the best option is either using JAR or WAR.
Using it with source is obviously not a good way to run on the server.
For creating a JAR, you can use the package
target in Maven.
For that, run the mvn package
command in the project-root directory.
It will generate the log like below:
Look for "Building JAR:" and copy the JAR to VPS.
Then run java -jar jarfilename.jar
.
BTW, do you have Java 14 on your machine? I think that's the root cause why your build isn't working.
<properties>
<java.version>14</java.version>
</properties>
Try changing it to older versions, and your build might start working.
英文:
If you want to take it to vps, the best option is either using JAR or war.
Using it with source is obviously not a good way to run on the server.
For creating jar, you can use package
target in maven.
for that run mvn package
command in the project-root directory.
It will generate the log like below
Look for Building jar:
and copy the jar to VPS.
then run java -jar jarfilename.jar
BTW, do you have java 14 on your machine? I think thats the root cause why your build isnt working.
<properties>
<java.version>14</java.version>
</properties>
Try changing it to older versions, and your build might start working.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论