【问题标题】:Running shell script with java on linux在linux上用java运行shell脚本
【发布时间】:2015-04-26 10:43:56
【问题描述】:

我正在将我的 Runescape 私有服务器从 Windows 迁移到 Linux。 服务器有一个 run.bat 来启动。

@echo off
title Project Kingscape
java -cp bin;deps/poi.jar;deps/mysql.jar;deps/mina.jar;deps/slf4j.jar;deps/slf4j-nop.jar;deps/jython.jar;log4j-1.2.15.jar;-server -XX:+AggressiveHeap -XX:MaxHeapFreeRatio=90 -XX:MinHeapFreeRatio=90 -XX:+DisableExplicitGC -XX:+RelaxAccessControlCheck -XX:+UseParallelGC -XX:CompileThreshold=1 -XX:ThreadStackSize=128 server.Server
pause

我将其转换为以下 .sh 脚本:

#!/bin/bash
java -classpath bin:deps/poi.jar:deps/mysql.jar:deps/mina.jar:deps/slf4j.jar:deps/slf4j-nop.jar:deps/jython.jar:log4j-1.2.15.jar:server.Server
read

我也安装了 OpenJdk 7。

当我尝试运行 run.sh 文件时,终端会显示以下内容:

Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)
where options include:
    -d32          use a 32-bit data model if available
    -d64          use a 64-bit data model if available
    -server       to select the "server" VM
    -zero         to select the "zero" VM
    -jamvm        to select the "jamvm" VM
    -avian        to select the "avian" VM
    -dcevm        to select the "dcevm" VM
                  The default VM is server.

    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
                  A : separated list of directories, JAR archives,
                  and ZIP archives to search for class files.
    -D<name>=<value>
                  set a system property
    -verbose:[class|gc|jni]
                  enable verbose output
    -version      print product version and exit
    -version:<value>
                  require the specified version to run
    -showversion  print product version and continue
    -jre-restrict-search | -no-jre-restrict-search
                  include/exclude user private JREs in the version search
    -? -help      print this help message
    -X            print help on non-standard options
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
                  enable assertions with specified granularity
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
                  disable assertions with specified granularity
    -esa | -enablesystemassertions
                  enable system assertions
    -dsa | -disablesystemassertions
                  disable system assertions
    -agentlib:<libname>[=<options>]
                  load native agent library <libname>, e.g. -agentlib:hprof
                  see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:<pathname>[=<options>]
                  load native agent library by full pathname
    -javaagent:<jarpath>[=<options>]
                  load Java programming language agent, see java.lang.instrument
    -splash:<imagepath>
                  show splash screen with specified image
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.

我知道我的语法可能是错误的,但很遗憾我没有任何 linux 知识。

谁能帮我找出问题所在?

【问题讨论】:

  • server.Server前面没有空格是错字吗?

标签: java linux shell


【解决方案1】:

您在类路径参数和主类名称之间缺少一个空格:

java -classpath bin:deps/poi.jar:deps/mysql.jar:deps/mina.jar:deps/slf4j.jar: \
deps/slf4j-nop.jar:deps/jython.jar:log4j-1.2.15.jar server.Server
                                                  ~ ~

除了使用冒号而不是分号作为路径分隔符之外,该命令应该与 Windows 上的命令完全相同,因此理想情况下:

java -cp bin:deps/poi.jar:deps/mysql.jar:deps/mina.jar:deps/slf4j.jar: \
deps/slf4j-nop.jar:deps/jython.jar:log4j-1.2.15.jar \
-server -XX:+AggressiveHeap -XX:MaxHeapFreeRatio=90 -XX:MinHeapFreeRatio=90 \
-XX:+DisableExplicitGC -XX:+RelaxAccessControlCheck -XX:+UseParallelGC \
-XX:CompileThreshold=1 -XX:ThreadStackSize=128 server.Server

请注意,类路径和初始命令中的 -server 参数之间也应该有一个空格。

【讨论】:

  • 谢谢,非常感谢。 2天的搜索,你刚刚修复它。我可以在 6 分钟内接受你的回答。
猜你喜欢
  • 2014-10-06
  • 2015-12-24
  • 2014-11-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多