我正在尝试制作一个java程序,它将使用我想要的任何用户名在离线模式下启动我的世界,这样我就可以拥有像Notch和deadmau5这样的用户名,我正在使用这个代码在mac和windows上启动它(目前在mac上测试):
public void startMacMinecraft(String username) throws IOException,
InterruptedException {
System.out.println(defaultDirectory());
String sysUser = System.getProperty("user.name");
String commandString = "java -cp "
+ defaultDirectory()
+ "/minecraft/bin/minecraft.jar:"
+ defaultDirectory()
+ "/minecraft/bin/lwjgl.jar:"
+ defaultDirectory()
+ "/minecraft/bin/lwjgl_util.jar:"
+ defaultDirectory()
+ "/minecraft/bin/jinput.jar: -Djava.library.path="
+ defaultDirectory()
+ "/minecraft/bin/natives -Xmx1024M -Xms512M net.minecraft.client.Minecraft '"
+ username + "'";
CommandLine command = CommandLine.parse(commandString);
DefaultExecutor executor = new DefaultExecutor();
int exitValue = executor.execute(command);
System.out.println(exitValue);
System.out.println("\nTry Two:\n");
String javaExe = System.getProperty("java.home") + "/bin/java";
}
public void startWinMinecraft(String username) throws IOException,
InterruptedException {
String sysUser = System.getProperty("user.name");
String commandString = "Java -Xms512m -Xmx1024m -cp \"%APPDATA%\\.minecraft\\bin\\*\" -Djava.library.path=\"%APPDATA%\\.minecraft\\bin\\natives net.minecraft.client.Minecraft \""
+ username + "\"";
CommandLine command = CommandLine.parse(commandString);
DefaultExecutor executor = new DefaultExecutor();
int exitValue = executor.execute(command);
System.out.println(exitValue);
}
private static String defaultDirectory() {
String OS = System.getProperty("os.name").toUpperCase();
if (OS.contains("WIN"))
return System.getenv("APPDATA");
else if (OS.contains("MAC"))
return System.getProperty("user.home") + "/Library/Application "
+ "Support";
else if (OS.contains("NUX"))
return System.getProperty("user.home");
return System.getProperty("user.dir");
}
我试图从我之前运行并从https://gaming.stackexchange.com/questions/46608/how-can-i-run-minecraft-in-offline-mode-on-os获得的这个 applescript 进行调整-x-and-still-have-my-name我将在这里粘贴:
property user_name : "Player"
display dialog "Enter A User Name" default answer "" buttons {"Cancel", "Continue"} default button 2
set the user_name to text returned of the result
set UsrApp to (path to current user folder)
set UsrApp_unx to POSIX path of UsrApp
set MineScript to "java -cp " & UsrApp_unx & "Library/Application\\ Support/minecraft/bin/minecraft.jar:" & UsrApp_unx & "Library/Application\\ Support/minecraft/bin/lwjgl.jar:" & UsrApp_unx & "Library/Application\\ Support/minecraft/bin/lwjgl_util.jar:" & UsrApp_unx & "Library/Application\\ Support/minecraft/bin/jinput.jar: -Djava.library.path=" & UsrApp_unx & "Library/Application\\ Support/minecraft/bin/natives -Xmx1024M -Xms512M net.minecraft.client.Minecraft '" & user_name & "'"
do shell script MineScript
当我运行applescript时,它工作得很好,但是当我运行我的改编版本时,它给了我一个找不到类的错误:
Logging in as: Player
/Users/Connor/Library/Application Support
Exception in thread "main" java.lang.NoClassDefFoundError: Support/minecraft/bin/minecraft/jar:/Users/Connor/Library/Application
Caused by: java.lang.ClassNotFoundException: Support.minecraft.bin.minecraft.jar:.Users.Connor.Library.Application
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)
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:377)
at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:160)
at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:147)
at info.connorbp.GUIApp.LoginPanel.startMacMinecraft(LoginPanel.java:137)
at info.connorbp.GUIApp.LoginPanel$1.actionPerformed(LoginPanel.java:82)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6375)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6140)
at java.awt.Container.processEvent(Container.java:2083)
at java.awt.Component.dispatchEventImpl(Component.java:4737)
at java.awt.Container.dispatchEventImpl(Container.java:2141)
at java.awt.Component.dispatchEvent(Component.java:4565)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4619)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4280)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4210)
at java.awt.Container.dispatchEventImpl(Container.java:2127)
at java.awt.Window.dispatchEventImpl(Window.java:2482)
at java.awt.Component.dispatchEvent(Component.java:4565)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:684)
at java.awt.EventQueue.access$000(EventQueue.java:85)
at java.awt.EventQueue$1.run(EventQueue.java:643)
at java.awt.EventQueue$1.run(EventQueue.java:641)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$2.run(EventQueue.java:657)
at java.awt.EventQueue$2.run(EventQueue.java:655)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:654)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
有谁知道我做错了什么或如何解决?
编辑:
更奇怪的是,我进入了 applescript 区域的 events 区域,找到了 applescript 正在运行的确切命令:
java -cp /Users/Connor/Library/Application\\ Support/minecraft/bin/minecraft.jar:/Users/Connor/Library/Application\\ Support/minecraft/bin/lwjgl.jar:/Users/Connor/Library/Application\\ Support/minecraft/bin/lwjgl_util.jar:/Users/Connor/Library/Application\\ Support/minecraft/bin/jinput.jar: -Djava.library.path=/Users/Connor/Library/Application\\ Support/minecraft/bin/natives -Xmx1024M -Xms512M net.minecraft.client.Minecraft 'username'
即使尝试运行直接来自applescript的脚本,我也遇到了另一个java.lang.NoClassDefFoundError错误,即使我直接从正在运行的applescript中获取了命令。