简体   繁体   English

将bat文件转换为包含java命令的脚本文件

[英]converting bat file to script file containing java command

I have an java application which contains run.bat file as below: 我有一个Java应用程序,其中包含run.bat文件,如下所示:

rem set path=D:/Applns/jdk1.5/bin
set classpath=.;lib/derby.jar;lib/mail.jar;lib/activation.jar;lib/commons-codec-1.3.jar
start javaw net.sf.veettukaaran.appclient.ApplicationController

when I run this run.bat in windows, the application works fine. 当我在Windows中运行该run.bat时,该应用程序运行正常。 But I want to run this in ubuntu 12.04 . 但是我想在ubuntu 12.04运行它。 So I tried to convert the run.bat to run.sh as below: 所以我尝试将run.bat转换为run.sh ,如下所示:

# /bin/sh
java -classpath './lib/derby.jar:lib/mail.jar:lib/activation.jar:lib/commons-codec-1.3.jar' net/sf/veettukaaran/appclient/ApplicationController

when I run this script by ./run.sh it gives me class not found exception as below: 当我通过./run.sh运行此脚本时,它为我提供了找不到类的异常,如下所示:

Caused by: java.lang.ClassNotFoundException: net.sf.veettukaaran.appclient.ApplicationController
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: net/sf/veettukaaran/appclient/ApplicationControll.  Program will exit.

Can somebody please point out what I am doing wrong ? 有人可以指出我做错了吗? I have checked the path of the specified jar files in classpath and class file and it is correct. 我已经检查了classpath和class文件中指定的jar文件的classpath ,它是正确的。 some other idea what might be wrong ? 其他想法可能是什么问题?

Thanks 谢谢

Replace the following 替换以下

java -classpath './lib/derby.jar:lib/mail.jar:lib/activation.jar:lib/commons-codec-1.3.jar' net/sf/veettukaaran/appclient/ApplicationController

with

java -classpath '.:./lib/derby.jar:lib/mail.jar:lib/activation.jar:lib/commons-codec-1.3.jar' net.sf.veettukaaran.appclient.ApplicationController

Notice that I have just added current directory . 注意,我刚刚添加了当前目录. to your classpath and corrected the class package name in front of the class by replacing / with . 到您的classpath并通过将/替换为来更正类前面的类包名称.

well I could run run.sh file finally. 好吧,我终于可以运行run.sh文件了。 It looks like below: 如下图所示:

# /bin/sh
java -cp ':./lib/derby.jar:./lib/mail.jar:./lib/activation.jar:./lib/commons-codec-1.3.jar' net.sf.veettukaaran.appclient.ApplicationController

After that I run this command: " dos2unix run.sh " and then I run ./run.sh . 之后,我运行以下命令:“ dos2unix run.sh ”,然后运行./run.sh and this way application gets executed. 这样就可以执行应用程序。

I thnak you all for your responses.. 我感谢大家的回应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM