如何从cmd运行jar参考

时间:2015-05-31 19:04:12

标签: java jar

我在java中下载了一个包,我打电话给package1,我创建了第二个包,我打电话给package2package2引用了package1

现在我需要将package1导出到JAR。我导出它(并在此过程中创建了一个清单文件,指定了包的main文件。)

从命令行(package1)运行java -jar package1.jar时,我如何连接"它到package2?也就是说,当我运行java -jar package1.jar时,我收到的错误是找不到package2中显示的特定类。

2 个答案:

答案 0 :(得分:1)

您应该在package2.jar命令行中添加-cpjava参数:

java -cp package2.jar -jar package1.jar

答案 1 :(得分:0)

至少应该在windows上使用:

import Foundation
import UIKit
import CoreMotion
import CoreLocation

public class Main {

    let motionManager = CMMotionActivityManager()
    var motionAvailable = CMMotionActivityManager.isActivityAvailable()
    var activityType = CMMotionActivity()
    typealias CMMotionActivityHandler = (CMMotionActivity!) -> Void
    let handler = CMMotionActivityHandler(motionManager) //Main.Type does not have a member named 'motionManager'
    public var testResult = "Not working"

    func run() -> String {

        if motionAvailable == true {

        motionManager.startActivityUpdatesToQueue(NSOperationQueue.mainQueue(), withHandler: handler) //Main does not have a member named 'handler'
        testResult = "Updating"

        }
        else {

        testResult = "No M8"
        }

        if activityType == CMMotionActivity().stationary {

        testResult == "Stationary"
        }
        else {

        testResult == "Not Stationary"
        }
    }

    init () {
    self.run()
    }

其中java -cp "package1.jar;package2.jar" com.example.app.Main 是主要课程包裹的路径,而com.example.app是您的主要课程。