我试图让这个run.bat在Linux CentOS上运行

时间:2013-10-04 21:00:29

标签: java linux batch-file centos

好吧,我正在努力让这个run.bat在CentOS上工作,并且我正在努力让它加载主类。在我的服务器上,它位于server / build / net / com / Server(mainclass)

这是我的run.bat

@echo off
title SunScape World 1 - Port 43594
cd ../build
"C:\Program Files\Java\jdk1.7.0_10\bin\java.exe" net/com/Server 43594
pause

以下是我在CentOS上使用的.sh

cd ../build
"java" .net.com.Server 43594
pause

以下是我收到的错误:

Exception in thread "main" java.lang.NoClassDefFoundError:          //pvpscape/build/net/com/Server
Caused by: java.lang.ClassNotFoundException: ..pvpscape.build.net.com.Server
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: ./pvpscape/build/net/com/Server. Program will exit.

1 个答案:

答案 0 :(得分:1)

嗨,

不幸的是,bat文件适用于DOS,不能在Linux上运行。 Linux的脚本语言是bash脚本(历史上是sh脚本)。以下是bash脚本的介绍指南:

http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html

回顾你的bat脚本,我看到你正在尝试进入“../build”目录,然后使用java运行带有参数43594的'net / com / Server'然后再进入休眠状态。在linux bash脚本中,我们将使用以下脚本完成此任务:

#!/bin/bash
cd ../build
java net/com/Server 43594
sleep 10

然后,您需要使脚本可执行:

chmod 755 run.sh

最后运行这个脚本:

# ./run.sh
相关问题