命令行参数是什么?

huangapple go评论44阅读模式
英文:

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 ->


4.0.0 org.springframework.boot
spring-boot-starter-parent
2.3.1.RELEASE
name
test1
1.0-SNAPSHOT
test1
My personal webpage

14

org.apache.tomcat.embed
tomcat-embed-jasper
provided

<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>


org.springframework.boot
spring-boot-maven-plugin

英文:

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 ->

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
         xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven 4.0.0.xsd&quot;&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;parent&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
    &lt;version&gt;2.3.1.RELEASE&lt;/version&gt;
    &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
&lt;/parent&gt;
&lt;groupId&gt;name&lt;/groupId&gt;
&lt;artifactId&gt;test1&lt;/artifactId&gt;
&lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
&lt;name&gt;test1&lt;/name&gt;
&lt;description&gt;My personal webpage&lt;/description&gt;

&lt;properties&gt;
    &lt;java.version&gt;14&lt;/java.version&gt;
&lt;/properties&gt;

&lt;dependencies&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.apache.tomcat.embed&lt;/groupId&gt;
        &lt;artifactId&gt;tomcat-embed-jasper&lt;/artifactId&gt;
        &lt;scope&gt;provided&lt;/scope&gt;
    &lt;/dependency&gt;

    &lt;dependency&gt;
        &lt;groupId&gt;org.webjars&lt;/groupId&gt;
        &lt;artifactId&gt;jquery&lt;/artifactId&gt;
        &lt;version&gt;1.9.1&lt;/version&gt;
    &lt;/dependency&gt;

    &lt;dependency&gt;
        &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
        &lt;artifactId&gt;lombok&lt;/artifactId&gt;
        &lt;version&gt;1.18.12&lt;/version&gt;
        &lt;scope&gt;provided&lt;/scope&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-mail&lt;/artifactId&gt;
        &lt;version&gt;2.2.5.RELEASE&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
        &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
        &lt;version&gt;4.0.0&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-jdbc&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;mysql&lt;/groupId&gt;
        &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;mysql&lt;/groupId&gt;
        &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
        &lt;scope&gt;runtime&lt;/scope&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
        &lt;scope&gt;test&lt;/scope&gt;
        &lt;exclusions&gt;
            &lt;exclusion&gt;
                &lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
                &lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
            &lt;/exclusion&gt;
        &lt;/exclusions&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
        &lt;artifactId&gt;spring-security-test&lt;/artifactId&gt;
        &lt;scope&gt;test&lt;/scope&gt;
    &lt;/dependency&gt;
&lt;/dependencies&gt;

&lt;build&gt;
    &lt;plugins&gt;
        &lt;plugin&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
        &lt;/plugin&gt;
    &lt;/plugins&gt;
&lt;/build&gt;

</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 a target 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#

&lt;properties&gt;
    &lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
    &lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
&lt;/properties&gt;

答案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.

&lt;properties&gt;
    &lt;java.version&gt;14&lt;/java.version&gt;
&lt;/properties&gt;

Try changing it to older versions, and your build might start working.

huangapple
  • 本文由 发表于 2020年8月1日 15:22:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/63202786.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定