代码如下 /** * $RCSfile: ,v $ * $Revision: $ * $Date: $ * * Copyright (C) 2004-2011 Jive Software. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jivesoftware.launcher;import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FilenameFilter; import java.io.InputStream; import java.lang.reflect.Method; import java.util.jar.JarOutputStream; import java.util.jar.Pack200;/** * */ public class Startup { /** * Default to this location if one has not been specified */ private static final String DEFAULT_LIB_DIR = "../lib"; public static void main(String[] args) { new Startup().start(args); } /** * Starts the server by loading and instantiating the bootstrap * container. Once the start method is called, the server is * started and the server starter should not be used again. * * @param args the arguments passed into this initial instance of Spark. */ private void start(String[] args) { // Setup the classpath using JiveClassLoader try { // Load up the bootstrap container final ClassLoader parent = findParentClassLoader(); File libDir; final String workingDirectory = System.getProperty("appdir"); if (workingDirectory == null) { libDir = new File(DEFAULT_LIB_DIR); } else { libDir = new File(new File(workingDirectory), "lib"); }
File pluginDir = new File(libDir.getParentFile(), "plugins"); // Unpack any pack files in lib. unpackArchives(libDir, true); // Unpack plugins. unpackArchives(pluginDir, true); // Load them into the classloader final ClassLoader loader = new JiveClassLoader(parent, libDir); Thread.currentThread().setContextClassLoader(loader); // Get class Class<?> sparkClass = loader.loadClass("org.jivesoftware.Spark"); Object instanceOfSpark = sparkClass.newInstance(); // Handle arguments if (args.length > 0) { String argument = args[0]; Method setArgument = sparkClass.getMethod("setArgument", String.class); setArgument.invoke(instanceOfSpark, argument); } Method startupMethod = sparkClass.getMethod("startup"); startupMethod.invoke(instanceOfSpark); } catch (Exception e) { e.printStackTrace(); } } /** * Locates the best class loader based on context (see class description). * * @return The best parent classloader to use */ private ClassLoader findParentClassLoader() { ClassLoader parent = Thread.currentThread().getContextClassLoader(); if (parent == null) { parent = this.getClass().getClassLoader(); if (parent == null) { parent = ClassLoader.getSystemClassLoader(); } } return parent; } /** * Converts any pack files in a directory into standard JAR files. Each * pack file will be deleted after being converted to a JAR. If no * pack files are found, this method does nothing. * * @param libDir the directory containing pack files. * @param printStatus true if status ellipses should be printed when unpacking. */ private void unpackArchives(File libDir, boolean printStatus) { // Get a list of all packed files in the lib directory. File[] packedFiles = libDir.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".pack"); } }); if (packedFiles == null) { // Do nothing since no .pack files were found return; } // Unpack each. boolean unpacked = false; for (File packedFile : packedFiles) { try { String jarName = packedFile.getName().substring(0, packedFile.getName().length() - ".pack".length()); // Delete JAR file with same name if it exists (could be due to upgrade // from old Wildfire release). File jarFile = new File(libDir, jarName); if (jarFile.exists()) { jarFile.delete(); } InputStream in = new BufferedInputStream(new FileInputStream(packedFile)); JarOutputStream out = new JarOutputStream(new BufferedOutputStream( new FileOutputStream(new File(libDir, jarName)))); Pack200.Unpacker unpacker = Pack200.newUnpacker(); // Print something so the user knows something is happening. if (printStatus) { System.out.print("."); } // Call the unpacker unpacker.unpack(in, out); in.close(); out.close(); packedFile.delete(); unpacked = true; } catch (Exception e) { e.printStackTrace(); } } // Print newline if unpacking happened. if (unpacked && printStatus) { System.out.println(); } } }
org.jivesoftware.Spark 类中 有没有名字是startup的方法
有的 代码如下: public final class Spark { public void startup() { if (System.getenv("APPDATA") != null && !System.getenv("APPDATA").equals("")) { USER_SPARK_HOME = System.getenv("APPDATA") + "/" + getUserConf(); } else { USER_SPARK_HOME = System.getProperties().getProperty("user.home") + "/" + getUserConf(); } String current = System.getProperty("java.library.path"); String classPath = System.getProperty("java.class.path"); // Set UIManager properties for JTree System.setProperty("apple.laf.useScreenMenuBar", "true"); /** Update Library Path **/ StringBuffer buf = new StringBuffer(); buf.append(current); buf.append(";"); SparkCompatibility sparkCompat = new SparkCompatibility(); try { // Absolute paths to a collection of files or directories to skip Collection<String> skipFiles = new HashSet<String>(); skipFiles.add(new File(USER_SPARK_HOME, "plugins").getAbsolutePath()); sparkCompat.transferConfig(USER_SPARK_HOME, skipFiles); } catch (IOException e) { // Do nothing } RESOURCE_DIRECTORY = initializeDirectory("resources"); BIN_DIRECTORY = initializeDirectory("bin"); LOG_DIRECTORY = initializeDirectory("logs"); USER_DIRECTORY = initializeDirectory("user"); PLUGIN_DIRECTORY = initializeDirectory("plugins"); XTRA_DIRECTORY = initializeDirectory("xtra"); // TODO implement copyEmoticonFiles(); final String workingDirectory = System.getProperty("appdir");
if (workingDirectory == null) { if (!RESOURCE_DIRECTORY.exists() || !LOG_DIRECTORY.exists() || !USER_DIRECTORY.exists() || !PLUGIN_DIRECTORY.exists() || !XTRA_DIRECTORY.exists()) { JOptionPane.showMessageDialog(new JFrame(), "Unable to create directories necessary for runtime.", "Spark Error", JOptionPane.ERROR_MESSAGE); System.exit(1); } } // This is the Spark.exe or Spark.dmg installed executable. else { // This is the installed executable. File workingDir = new File(workingDirectory); RESOURCE_DIRECTORY = initializeDirectory(workingDir, "resources"); BIN_DIRECTORY = initializeDirectory(workingDir, "bin"); File emoticons = new File(XTRA_DIRECTORY, "emoticons").getAbsoluteFile(); if(!emoticons.exists()){ //Copy emoticon files from install directory to the spark user home directory }
LOG_DIRECTORY = initializeDirectory("logs"); LOG_DIRECTORY = new File(USER_SPARK_HOME, "logs").getAbsoluteFile(); LOG_DIRECTORY.mkdirs(); try { buf.append(RESOURCE_DIRECTORY.getCanonicalPath()).append(";"); } catch (IOException e) { e.printStackTrace(); } } // Set default language set by the user. loadLanguage(); /** * Loads the LookandFeel */ loadLookAndFeel(); buf.append(classPath); buf.append(";").append(RESOURCE_DIRECTORY.getAbsolutePath()); // Update System Properties System.setProperty("java.library.path", buf.toString()); System.setProperty("sun.java2d.noddraw", "true"); System.setProperty("file.encoding", "UTF-8"); SwingUtilities.invokeLater(new Runnable() { public void run() { // Start Application new Spark(); } }); //load plugins before Workspace initialization to avoid any UI delays //during plugin rendering final PluginManager pluginManager = PluginManager.getInstance(); pluginManager.loadPlugins(); installBaseUIProperties(); if (Default.getBoolean("CHANGE_COLORS_DISABLED")) { ColorSettingManager.restoreDefault(); } try { EventQueue.invokeAndWait(new Runnable(){ public void run() { final LoginDialog dialog = UIComponentRegistry.createLoginDialog(); dialog.invoke(new JFrame()); } }); } catch(Exception ex) { ex.printStackTrace(); } } }
/**
* $RCSfile: ,v $
* $Revision: $
* $Date: $
*
* Copyright (C) 2004-2011 Jive Software. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.launcher;import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.jar.JarOutputStream;
import java.util.jar.Pack200;/**
*
*/
public class Startup { /**
* Default to this location if one has not been specified
*/
private static final String DEFAULT_LIB_DIR = "../lib"; public static void main(String[] args) {
new Startup().start(args);
} /**
* Starts the server by loading and instantiating the bootstrap
* container. Once the start method is called, the server is
* started and the server starter should not be used again.
*
* @param args the arguments passed into this initial instance of Spark.
*/
private void start(String[] args) {
// Setup the classpath using JiveClassLoader
try {
// Load up the bootstrap container
final ClassLoader parent = findParentClassLoader(); File libDir;
final String workingDirectory = System.getProperty("appdir");
if (workingDirectory == null) {
libDir = new File(DEFAULT_LIB_DIR);
}
else {
libDir = new File(new File(workingDirectory), "lib");
}
File pluginDir = new File(libDir.getParentFile(), "plugins"); // Unpack any pack files in lib.
unpackArchives(libDir, true); // Unpack plugins.
unpackArchives(pluginDir, true); // Load them into the classloader
final ClassLoader loader = new JiveClassLoader(parent, libDir); Thread.currentThread().setContextClassLoader(loader); // Get class
Class<?> sparkClass = loader.loadClass("org.jivesoftware.Spark");
Object instanceOfSpark = sparkClass.newInstance(); // Handle arguments
if (args.length > 0) {
String argument = args[0];
Method setArgument = sparkClass.getMethod("setArgument", String.class);
setArgument.invoke(instanceOfSpark, argument);
} Method startupMethod = sparkClass.getMethod("startup");
startupMethod.invoke(instanceOfSpark);
}
catch (Exception e) {
e.printStackTrace();
}
} /**
* Locates the best class loader based on context (see class description).
*
* @return The best parent classloader to use
*/
private ClassLoader findParentClassLoader() {
ClassLoader parent = Thread.currentThread().getContextClassLoader();
if (parent == null) {
parent = this.getClass().getClassLoader();
if (parent == null) {
parent = ClassLoader.getSystemClassLoader();
}
}
return parent;
} /**
* Converts any pack files in a directory into standard JAR files. Each
* pack file will be deleted after being converted to a JAR. If no
* pack files are found, this method does nothing.
*
* @param libDir the directory containing pack files.
* @param printStatus true if status ellipses should be printed when unpacking.
*/
private void unpackArchives(File libDir, boolean printStatus) {
// Get a list of all packed files in the lib directory.
File[] packedFiles = libDir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".pack");
}
}); if (packedFiles == null) {
// Do nothing since no .pack files were found
return;
} // Unpack each.
boolean unpacked = false;
for (File packedFile : packedFiles) {
try {
String jarName = packedFile.getName().substring(0,
packedFile.getName().length() - ".pack".length());
// Delete JAR file with same name if it exists (could be due to upgrade
// from old Wildfire release).
File jarFile = new File(libDir, jarName);
if (jarFile.exists()) {
jarFile.delete();
} InputStream in = new BufferedInputStream(new FileInputStream(packedFile));
JarOutputStream out = new JarOutputStream(new BufferedOutputStream(
new FileOutputStream(new File(libDir, jarName))));
Pack200.Unpacker unpacker = Pack200.newUnpacker();
// Print something so the user knows something is happening.
if (printStatus) {
System.out.print(".");
}
// Call the unpacker
unpacker.unpack(in, out); in.close();
out.close();
packedFile.delete();
unpacked = true;
}
catch (Exception e) {
e.printStackTrace();
}
}
// Print newline if unpacking happened.
if (unpacked && printStatus) {
System.out.println();
}
}
}
public final class Spark {
public void startup() {
if (System.getenv("APPDATA") != null && !System.getenv("APPDATA").equals("")) {
USER_SPARK_HOME = System.getenv("APPDATA") + "/" + getUserConf();
} else {
USER_SPARK_HOME = System.getProperties().getProperty("user.home") + "/" + getUserConf();
} String current = System.getProperty("java.library.path");
String classPath = System.getProperty("java.class.path"); // Set UIManager properties for JTree
System.setProperty("apple.laf.useScreenMenuBar", "true"); /** Update Library Path **/
StringBuffer buf = new StringBuffer();
buf.append(current);
buf.append(";"); SparkCompatibility sparkCompat = new SparkCompatibility();
try {
// Absolute paths to a collection of files or directories to skip
Collection<String> skipFiles = new HashSet<String>();
skipFiles.add(new File(USER_SPARK_HOME, "plugins").getAbsolutePath()); sparkCompat.transferConfig(USER_SPARK_HOME, skipFiles);
} catch (IOException e) {
// Do nothing
}
RESOURCE_DIRECTORY = initializeDirectory("resources");
BIN_DIRECTORY = initializeDirectory("bin");
LOG_DIRECTORY = initializeDirectory("logs");
USER_DIRECTORY = initializeDirectory("user");
PLUGIN_DIRECTORY = initializeDirectory("plugins");
XTRA_DIRECTORY = initializeDirectory("xtra");
// TODO implement copyEmoticonFiles();
final String workingDirectory = System.getProperty("appdir");
if (workingDirectory == null) { if (!RESOURCE_DIRECTORY.exists() || !LOG_DIRECTORY.exists() || !USER_DIRECTORY.exists() || !PLUGIN_DIRECTORY.exists() || !XTRA_DIRECTORY.exists()) {
JOptionPane.showMessageDialog(new JFrame(), "Unable to create directories necessary for runtime.", "Spark Error", JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
}
// This is the Spark.exe or Spark.dmg installed executable. else {
// This is the installed executable.
File workingDir = new File(workingDirectory);
RESOURCE_DIRECTORY = initializeDirectory(workingDir, "resources");
BIN_DIRECTORY = initializeDirectory(workingDir, "bin");
File emoticons = new File(XTRA_DIRECTORY, "emoticons").getAbsoluteFile();
if(!emoticons.exists()){ //Copy emoticon files from install directory to the spark user home directory
}
LOG_DIRECTORY = initializeDirectory("logs");
LOG_DIRECTORY = new File(USER_SPARK_HOME, "logs").getAbsoluteFile();
LOG_DIRECTORY.mkdirs();
try {
buf.append(RESOURCE_DIRECTORY.getCanonicalPath()).append(";");
}
catch (IOException e) {
e.printStackTrace();
}
} // Set default language set by the user.
loadLanguage(); /**
* Loads the LookandFeel
*/
loadLookAndFeel();
buf.append(classPath);
buf.append(";").append(RESOURCE_DIRECTORY.getAbsolutePath()); // Update System Properties
System.setProperty("java.library.path", buf.toString());
System.setProperty("sun.java2d.noddraw", "true");
System.setProperty("file.encoding", "UTF-8"); SwingUtilities.invokeLater(new Runnable() {
public void run() {
// Start Application
new Spark();
}
}); //load plugins before Workspace initialization to avoid any UI delays
//during plugin rendering
final PluginManager pluginManager = PluginManager.getInstance();
pluginManager.loadPlugins(); installBaseUIProperties(); if (Default.getBoolean("CHANGE_COLORS_DISABLED")) {
ColorSettingManager.restoreDefault();
} try {
EventQueue.invokeAndWait(new Runnable(){
public void run() {
final LoginDialog dialog = UIComponentRegistry.createLoginDialog();
dialog.invoke(new JFrame());
}
});
}
catch(Exception ex) {
ex.printStackTrace();
}
}
}
String argument = args[0];
Method setArgument = sparkClass.getMethod("setArgument", String.class);
setArgument.invoke(instanceOfSpark, argument);
}Startup.java中这几句是有问题的 Spark.java中 没有setArgument方法
public void setArgument(String arguments) {
ARGUMENTS = arguments;
}
solution:把src文件夹下面的resources文件里面所有的文件及.jar包都copy 到bin文件中,问题解决。