我在 eclipse 中创建了 java 项目,没有 main 方法,右键单击项目,导出为 jar 并创建。现在我尝试从 CMD 执行 jar,但显示错误。 在executecookie.jar 中没有主要 list 属性
即使我在 CMD 中尝试过以下命令:
java -jar executecookie.jar
java -jar executecookie.jar com.cookie.CookieApp
我的代码是:
public class CookieApp {
public static String CookieMethod()
{
System.setProperty("webdriver.chrome.driver","/SD_WorkspaceNew/CookieJar/chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("http://localhost:8080/qcbin/rest/is-authenticated?login-form-required=y");
.......<br/>
return CookieResult;<br/>
}
}
是否可以在没有 main 方法的情况下从 CMD 执行 jar 文件?如果是,我该如何解决这个问题?
最佳答案
您收到错误并不是因为您没有 main 方法。这是因为您没有 list 文件和正确打包的 jar 文件所需的其他属性。检查JAR file specification了解更多详情。
Is this possible to execute the jar file from CMD without main method? if it is yes, how can i resolve this issue?
您是否尝试过在系统中执行其他 jar 文件?
java -jar file.jar
这个命令确实是执行jar文件的正确方法。
关于java - java中是否可以不使用main方法来执行jar文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42017392/