簡體   English   中英

為什么此Java jar無法正常工作?

[英]Why isn't this Java jar working?

當我運行下面的代碼時,出現以下錯誤。

C:\Documents and Settings\BOS\Desktop\test>java -jar test.jar
Exception in thread "main" java.lang.NullPointerException
        at sun.launcher.LauncherHelper.getMainClassFromJar(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

我在\\ test目錄= crimson.jar robosuite-api.jar和test.jar中有這些文件。

這是他們舉一個機器人的例子?

import com.kapowtech.robosuite.api.java.rql.*;
public class SimpleRunRobot {
public static void main(String[] args) {
if (args.length < 1) {
System.out.println("Usage: RunRobot <robotURL>");
System.exit(1);
}
try {
// Run the robot
RQLResult result =
RobotExecutor.getRobotExecutor().execute(args[0]);
// Output the results
System.out.println(result);
}
catch (RQLException e) {
System.out.println("An error occurred: " + e);
}
}
}

為什么這會給我這個未知來源錯誤?

 package robosuite.robots;

    import com.kapowtech.robosuite.api.java.rql.RQLException;
    import com.kapowtech.robosuite.api.java.rql.RQLResult;
    import com.kapowtech.robosuite.api.java.rql.RobotExecutor;
    import com.kapowtech.robosuite.api.java.rql.construct.RQLObjects;


    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.List;



       /**
         * 
         * <p>
         * This is an autogenerated class. It has been generated from the
         * <code>library:/test.robot</code> file.
         *
         * @author RoboSuite
         */
    public class Test {

        // ----------------------------------------------------------------------
        // Class fields
        // ----------------------------------------------------------------------

        private static final String ROBOT_URL = "library:/test.robot";
        private static final RobotExecutor ROBOT_EXECUTOR = RobotExecutor.getRobotExecutor(SingletonRQLEngine.getInstance());
        private static final Converter CONVERTER = Converter.getInstance();



  // ----------------------------------------------------------------------
    // Constructors
    // ----------------------------------------------------------------------

    /**
     * Creates a new Test instance that can be used to execute the
     * <code>library:/test.robot</code>.
     */
        public Test() {
        }

        // ----------------------------------------------------------------------
        // Instance methods
        // ----------------------------------------------------------------------

        /**
         * Executes this robot.
         * 
         * @param test an input object to the robot. 
         * @return an array of output objects.
         * @throws java.io.IOException if the execution fails for some reason.
         */
        public Testst[] run(Test0 test) throws java.io.IOException {
            try {
                // Prepare input objects
                List parameters = new ArrayList();
                parameters.add(test);

                RQLObjects inputObjects = CONVERTER.convertBeansToRQLObjects(parameters);

                // Run robot
                RQLResult rqlResult = ROBOT_EXECUTOR.execute(ROBOT_URL, inputObjects);

                // Extract output objects
                RQLObjects outputObjects = rqlResult.getOutputObjects();
                List result = CONVERTER.convertRQLObjectsToBeans(outputObjects);
                return (Testst[]) result.toArray(new Testst[result.size()]);
            } catch (RQLException e) {
                throw new IOException(e.toString());
            }
        }


        /* ------------------------------------------------------------------- */
    }

如果您使用的是Java 7,請閱讀此內容。

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7067922

您必須在META-INF / manifest文件中添加具有main()方法的類的名稱。

這是具有更多信息的鏈接: http : //java.sun.com/developer/Books/javaprogramming/JAR/basics/manifest.html

謝謝。

嘗試

java -cp test.jar

還包括其他.jar文件

如果使用清單文件,請確保已定義主類。 例如

Main-Class: test.MyApp

為什么這會給我這個未知來源錯誤?

“未知來源”消息不是錯誤。 JVM告訴您正在執行的代碼已編譯,沒有任何調試信息。 例如,使用-gLnone選項。 結果,通常不會包含在堆棧跟蹤中的源文件名和行號不可用。

在這種情況下,代碼是JVM內部某些平台特定的東西。 不用擔心...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM