Skip to main content



      Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Trouble running code on Windows(Can't run code developed on Linux on Windows b/c missing dependencies)
Trouble running code on Windows [message #870853] Wed, 09 May 2012 19:22 Go to next message
Eclipse UserFriend
I have a bit of a strange issue. I am developing an application using the WindowBuilder and associated libraries. The program works great on my 32-bit Linux box that I have been developing on. However I have two issues.

1) When running the jar on a 64-bit machine, it fails, which makes sense because I packaged the 32-bit libraries in the jar. If someone knows how to make the jar dual architecture, help would be greatly appreciated.

2) More importantly (as my client is chiefly 32-bit Windows XP as most of the world is) I can't run it on Windows. I actually moved the project over to a windows box, set up the WindowBuilder libraries in Eclipse, and recompiled, and it did work. However when I try to use my jar created in Linux, it fails with a message that I will attach (something about needing swt_gtk libraries). Now I'm somewhat new with java, but isn't the goal interoperability? I just find it strange that WindowBuilder seems to be using platform specific code. That being said, any ways around this (ways to make the program work on multiple operating systems) would be fantastic.

Sincerely,
Jesse

Also, I had posted this in the WindowBuilder section, but they sent me here. So my apologies for the duplicates.
Re: Trouble running code on Windows [message #871028 is a reply to message #870853] Thu, 10 May 2012 10:51 Go to previous messageGo to next message
Eclipse UserFriend
Hi there Jesse, you need to download the swt jars for each operative system. Java is portable, but SWT not totally.
Re: Trouble running code on Windows [message #871116 is a reply to message #871028] Thu, 10 May 2012 19:01 Go to previous messageGo to next message
Eclipse UserFriend
How would you go about doing that in Eclipse? Thanks
Re: Trouble running code on Windows [message #871295 is a reply to message #871116] Fri, 11 May 2012 15:23 Go to previous messageGo to next message
Eclipse UserFriend
On 5/10/12 7:01 PM, Jesse Osiecki wrote:
> How would you go about doing that in Eclipse? Thanks

You have 2 basic choices:
1) Package separately for each platform (win32/win64/gtk32/gtk64/etc)
Not too difficult with a little ANT-fu. It does mean you then have
multiple platforms end products. This is the route Eclipse itself has taken.

2) Package all the different platform jars and decide at runtime which
set to load.
There are some tips on how to do this here:
http://stackoverflow.com/questions/3959556/problems-with-loading-resources-during-execution

This is how I've tackled the problem. Each SWT platform jar goes in its
own subfolder win32\win64\etc. The main class detects which platform its
running on and then creates a new classloader with URLs that include
that subfolder in the path. It then launches the rest of the application.

All this is packaged up into one runnable jar using ANT.
Re: Trouble running code on Windows [message #871311 is a reply to message #871295] Fri, 11 May 2012 17:26 Go to previous messageGo to next message
Eclipse UserFriend
I'm messing with that code given in the error trying to get it to chainload my program. Two questions.

1) What does your ant build script look like?

2)I have completely forgotten and will probably ask later Cool
Re: Trouble running code on Windows [message #871578 is a reply to message #871311] Mon, 14 May 2012 09:04 Go to previous messageGo to next message
Eclipse UserFriend
Attached are the build.xml and the main starting class

I've modified them slightly from the ones I actually use to remove any
possible reference to stuff I do for work, so there might be some typos
in there.

It should all be fairly obvious, let me know if you have questions.

In the build I'm currently only packaging for Win32/64. Its obvious and
easy to expand to all SWT platforms.

On 5/11/12 5:26 PM, Jesse Osiecki wrote:
> I'm messing with that code given in the error trying to get it to
> chainload my program. Two questions.
>
> 1) What does your ant build script look like?
>
> 2)I have completely forgotten and will probably ask later 8)


package com.andi;

import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Properties;

public class Main {
private static final String LAUNCH_CLASS = "com.andi.TheRealMainClass";

public static void main(final String[] args) {
final String osArch = System.getProperty("os.arch");
final String osName = System.getProperty("os.name").toUpperCase();

final boolean is32bit = !osArch.contains("64");
final boolean isWindows = osName.contains("WINDOWS");
final boolean isLinux = osName.contains("LINUX") || osName.contains("NIX");
final boolean isMac = osName.contains("MAC");

String path = "";
if (isWindows)
path = "win";
else if (isLinux)
path = "gtk";
else if (isMac)
path = "mac";
if (is32bit)
path = path + "32";
else
path = path + "64";
System.out.println("Selected SWT classpath platform: " + path);
final ClassLoader parent = Main.class.getClassLoader();

final ArrayList<URL> urls = new ArrayList<URL>();
try {
final InputStream stream = parent.getResourceAsStream("libjars.properties");
final Properties properties = new Properties();
properties.load(stream);
stream.close();
String libs = (String) properties.get("contents");
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + aLib + "!/"));
}
libs = (String) properties.get("contents." + path);
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + path + "/" + aLib + "!/"));
}
} catch (final Throwable e1) {
}

try {
if (urls.size() > 0) {
final Method m1 = parent.getClass().getDeclaredMethod("addURL", URL.class);
m1.setAccessible(true);
for (final URL url : urls) {
m1.invoke(parent, url);
}
for (final URL url : ((URLClassLoader) parent).getURLs()) {
System.out.println(url);
}
}
final Class<?> class1 = parent.loadClass(LAUNCH_CLASS);
final Method method = class1.getMethod("launch", String[].class);
final Object[] methodArgs = new Object[] { args };
method.invoke(null, methodArgs);
} catch (final Throwable e) {
e.printStackTrace();
}
}

}
  • Attachment: build.xml
    (Size: 2.23KB, Downloaded 171 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 204 times)
Re: Trouble running code on Windows [message #871580 is a reply to message #871311] Mon, 14 May 2012 09:04 Go to previous messageGo to next message
Eclipse UserFriend
Attached are the build.xml and the main starting class

I've modified them slightly from the ones I actually use to remove any
possible reference to stuff I do for work, so there might be some typos
in there.

It should all be fairly obvious, let me know if you have questions.

In the build I'm currently only packaging for Win32/64. Its obvious and
easy to expand to all SWT platforms.

On 5/11/12 5:26 PM, Jesse Osiecki wrote:
> I'm messing with that code given in the error trying to get it to
> chainload my program. Two questions.
>
> 1) What does your ant build script look like?
>
> 2)I have completely forgotten and will probably ask later 8)


package com.andi;

import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Properties;

public class Main {
private static final String LAUNCH_CLASS = "com.andi.TheRealMainClass";

public static void main(final String[] args) {
final String osArch = System.getProperty("os.arch");
final String osName = System.getProperty("os.name").toUpperCase();

final boolean is32bit = !osArch.contains("64");
final boolean isWindows = osName.contains("WINDOWS");
final boolean isLinux = osName.contains("LINUX") || osName.contains("NIX");
final boolean isMac = osName.contains("MAC");

String path = "";
if (isWindows)
path = "win";
else if (isLinux)
path = "gtk";
else if (isMac)
path = "mac";
if (is32bit)
path = path + "32";
else
path = path + "64";
System.out.println("Selected SWT classpath platform: " + path);
final ClassLoader parent = Main.class.getClassLoader();

final ArrayList<URL> urls = new ArrayList<URL>();
try {
final InputStream stream = parent.getResourceAsStream("libjars.properties");
final Properties properties = new Properties();
properties.load(stream);
stream.close();
String libs = (String) properties.get("contents");
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + aLib + "!/"));
}
libs = (String) properties.get("contents." + path);
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + path + "/" + aLib + "!/"));
}
} catch (final Throwable e1) {
}

try {
if (urls.size() > 0) {
final Method m1 = parent.getClass().getDeclaredMethod("addURL", URL.class);
m1.setAccessible(true);
for (final URL url : urls) {
m1.invoke(parent, url);
}
for (final URL url : ((URLClassLoader) parent).getURLs()) {
System.out.println(url);
}
}
final Class<?> class1 = parent.loadClass(LAUNCH_CLASS);
final Method method = class1.getMethod("launch", String[].class);
final Object[] methodArgs = new Object[] { args };
method.invoke(null, methodArgs);
} catch (final Throwable e) {
e.printStackTrace();
}
}

}
  • Attachment: build.xml
    (Size: 2.23KB, Downloaded 252 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 183 times)
Re: Trouble running code on Windows [message #871583 is a reply to message #871311] Mon, 14 May 2012 09:04 Go to previous messageGo to next message
Eclipse UserFriend
Attached are the build.xml and the main starting class

I've modified them slightly from the ones I actually use to remove any
possible reference to stuff I do for work, so there might be some typos
in there.

It should all be fairly obvious, let me know if you have questions.

In the build I'm currently only packaging for Win32/64. Its obvious and
easy to expand to all SWT platforms.

On 5/11/12 5:26 PM, Jesse Osiecki wrote:
> I'm messing with that code given in the error trying to get it to
> chainload my program. Two questions.
>
> 1) What does your ant build script look like?
>
> 2)I have completely forgotten and will probably ask later 8)


package com.andi;

import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Properties;

public class Main {
private static final String LAUNCH_CLASS = "com.andi.TheRealMainClass";

public static void main(final String[] args) {
final String osArch = System.getProperty("os.arch");
final String osName = System.getProperty("os.name").toUpperCase();

final boolean is32bit = !osArch.contains("64");
final boolean isWindows = osName.contains("WINDOWS");
final boolean isLinux = osName.contains("LINUX") || osName.contains("NIX");
final boolean isMac = osName.contains("MAC");

String path = "";
if (isWindows)
path = "win";
else if (isLinux)
path = "gtk";
else if (isMac)
path = "mac";
if (is32bit)
path = path + "32";
else
path = path + "64";
System.out.println("Selected SWT classpath platform: " + path);
final ClassLoader parent = Main.class.getClassLoader();

final ArrayList<URL> urls = new ArrayList<URL>();
try {
final InputStream stream = parent.getResourceAsStream("libjars.properties");
final Properties properties = new Properties();
properties.load(stream);
stream.close();
String libs = (String) properties.get("contents");
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + aLib + "!/"));
}
libs = (String) properties.get("contents." + path);
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + path + "/" + aLib + "!/"));
}
} catch (final Throwable e1) {
}

try {
if (urls.size() > 0) {
final Method m1 = parent.getClass().getDeclaredMethod("addURL", URL.class);
m1.setAccessible(true);
for (final URL url : urls) {
m1.invoke(parent, url);
}
for (final URL url : ((URLClassLoader) parent).getURLs()) {
System.out.println(url);
}
}
final Class<?> class1 = parent.loadClass(LAUNCH_CLASS);
final Method method = class1.getMethod("launch", String[].class);
final Object[] methodArgs = new Object[] { args };
method.invoke(null, methodArgs);
} catch (final Throwable e) {
e.printStackTrace();
}
}

}
  • Attachment: build.xml
    (Size: 2.23KB, Downloaded 188 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 231 times)
Re: Trouble running code on Windows [message #871586 is a reply to message #871311] Mon, 14 May 2012 09:04 Go to previous messageGo to next message
Eclipse UserFriend
Attached are the build.xml and the main starting class

I've modified them slightly from the ones I actually use to remove any
possible reference to stuff I do for work, so there might be some typos
in there.

It should all be fairly obvious, let me know if you have questions.

In the build I'm currently only packaging for Win32/64. Its obvious and
easy to expand to all SWT platforms.

On 5/11/12 5:26 PM, Jesse Osiecki wrote:
> I'm messing with that code given in the error trying to get it to
> chainload my program. Two questions.
>
> 1) What does your ant build script look like?
>
> 2)I have completely forgotten and will probably ask later 8)


package com.andi;

import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Properties;

public class Main {
private static final String LAUNCH_CLASS = "com.andi.TheRealMainClass";

public static void main(final String[] args) {
final String osArch = System.getProperty("os.arch");
final String osName = System.getProperty("os.name").toUpperCase();

final boolean is32bit = !osArch.contains("64");
final boolean isWindows = osName.contains("WINDOWS");
final boolean isLinux = osName.contains("LINUX") || osName.contains("NIX");
final boolean isMac = osName.contains("MAC");

String path = "";
if (isWindows)
path = "win";
else if (isLinux)
path = "gtk";
else if (isMac)
path = "mac";
if (is32bit)
path = path + "32";
else
path = path + "64";
System.out.println("Selected SWT classpath platform: " + path);
final ClassLoader parent = Main.class.getClassLoader();

final ArrayList<URL> urls = new ArrayList<URL>();
try {
final InputStream stream = parent.getResourceAsStream("libjars.properties");
final Properties properties = new Properties();
properties.load(stream);
stream.close();
String libs = (String) properties.get("contents");
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + aLib + "!/"));
}
libs = (String) properties.get("contents." + path);
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + path + "/" + aLib + "!/"));
}
} catch (final Throwable e1) {
}

try {
if (urls.size() > 0) {
final Method m1 = parent.getClass().getDeclaredMethod("addURL", URL.class);
m1.setAccessible(true);
for (final URL url : urls) {
m1.invoke(parent, url);
}
for (final URL url : ((URLClassLoader) parent).getURLs()) {
System.out.println(url);
}
}
final Class<?> class1 = parent.loadClass(LAUNCH_CLASS);
final Method method = class1.getMethod("launch", String[].class);
final Object[] methodArgs = new Object[] { args };
method.invoke(null, methodArgs);
} catch (final Throwable e) {
e.printStackTrace();
}
}

}
  • Attachment: build.xml
    (Size: 2.23KB, Downloaded 199 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 172 times)
Re: Trouble running code on Windows [message #871587 is a reply to message #871311] Mon, 14 May 2012 09:04 Go to previous messageGo to next message
Eclipse UserFriend
Attached are the build.xml and the main starting class

I've modified them slightly from the ones I actually use to remove any
possible reference to stuff I do for work, so there might be some typos
in there.

It should all be fairly obvious, let me know if you have questions.

In the build I'm currently only packaging for Win32/64. Its obvious and
easy to expand to all SWT platforms.

On 5/11/12 5:26 PM, Jesse Osiecki wrote:
> I'm messing with that code given in the error trying to get it to
> chainload my program. Two questions.
>
> 1) What does your ant build script look like?
>
> 2)I have completely forgotten and will probably ask later 8)


package com.andi;

import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Properties;

public class Main {
private static final String LAUNCH_CLASS = "com.andi.TheRealMainClass";

public static void main(final String[] args) {
final String osArch = System.getProperty("os.arch");
final String osName = System.getProperty("os.name").toUpperCase();

final boolean is32bit = !osArch.contains("64");
final boolean isWindows = osName.contains("WINDOWS");
final boolean isLinux = osName.contains("LINUX") || osName.contains("NIX");
final boolean isMac = osName.contains("MAC");

String path = "";
if (isWindows)
path = "win";
else if (isLinux)
path = "gtk";
else if (isMac)
path = "mac";
if (is32bit)
path = path + "32";
else
path = path + "64";
System.out.println("Selected SWT classpath platform: " + path);
final ClassLoader parent = Main.class.getClassLoader();

final ArrayList<URL> urls = new ArrayList<URL>();
try {
final InputStream stream = parent.getResourceAsStream("libjars.properties");
final Properties properties = new Properties();
properties.load(stream);
stream.close();
String libs = (String) properties.get("contents");
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + aLib + "!/"));
}
libs = (String) properties.get("contents." + path);
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + path + "/" + aLib + "!/"));
}
} catch (final Throwable e1) {
}

try {
if (urls.size() > 0) {
final Method m1 = parent.getClass().getDeclaredMethod("addURL", URL.class);
m1.setAccessible(true);
for (final URL url : urls) {
m1.invoke(parent, url);
}
for (final URL url : ((URLClassLoader) parent).getURLs()) {
System.out.println(url);
}
}
final Class<?> class1 = parent.loadClass(LAUNCH_CLASS);
final Method method = class1.getMethod("launch", String[].class);
final Object[] methodArgs = new Object[] { args };
method.invoke(null, methodArgs);
} catch (final Throwable e) {
e.printStackTrace();
}
}

}
  • Attachment: build.xml
    (Size: 2.23KB, Downloaded 172 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 195 times)
Re: Trouble running code on Windows [message #871589 is a reply to message #871311] Mon, 14 May 2012 09:04 Go to previous messageGo to next message
Eclipse UserFriend
Attached are the build.xml and the main starting class

I've modified them slightly from the ones I actually use to remove any
possible reference to stuff I do for work, so there might be some typos
in there.

It should all be fairly obvious, let me know if you have questions.

In the build I'm currently only packaging for Win32/64. Its obvious and
easy to expand to all SWT platforms.

On 5/11/12 5:26 PM, Jesse Osiecki wrote:
> I'm messing with that code given in the error trying to get it to
> chainload my program. Two questions.
>
> 1) What does your ant build script look like?
>
> 2)I have completely forgotten and will probably ask later 8)


package com.andi;

import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Properties;

public class Main {
private static final String LAUNCH_CLASS = "com.andi.TheRealMainClass";

public static void main(final String[] args) {
final String osArch = System.getProperty("os.arch");
final String osName = System.getProperty("os.name").toUpperCase();

final boolean is32bit = !osArch.contains("64");
final boolean isWindows = osName.contains("WINDOWS");
final boolean isLinux = osName.contains("LINUX") || osName.contains("NIX");
final boolean isMac = osName.contains("MAC");

String path = "";
if (isWindows)
path = "win";
else if (isLinux)
path = "gtk";
else if (isMac)
path = "mac";
if (is32bit)
path = path + "32";
else
path = path + "64";
System.out.println("Selected SWT classpath platform: " + path);
final ClassLoader parent = Main.class.getClassLoader();

final ArrayList<URL> urls = new ArrayList<URL>();
try {
final InputStream stream = parent.getResourceAsStream("libjars.properties");
final Properties properties = new Properties();
properties.load(stream);
stream.close();
String libs = (String) properties.get("contents");
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + aLib + "!/"));
}
libs = (String) properties.get("contents." + path);
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + path + "/" + aLib + "!/"));
}
} catch (final Throwable e1) {
}

try {
if (urls.size() > 0) {
final Method m1 = parent.getClass().getDeclaredMethod("addURL", URL.class);
m1.setAccessible(true);
for (final URL url : urls) {
m1.invoke(parent, url);
}
for (final URL url : ((URLClassLoader) parent).getURLs()) {
System.out.println(url);
}
}
final Class<?> class1 = parent.loadClass(LAUNCH_CLASS);
final Method method = class1.getMethod("launch", String[].class);
final Object[] methodArgs = new Object[] { args };
method.invoke(null, methodArgs);
} catch (final Throwable e) {
e.printStackTrace();
}
}

}
  • Attachment: build.xml
    (Size: 2.23KB, Downloaded 230 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 189 times)
Re: Trouble running code on Windows [message #871591 is a reply to message #871311] Mon, 14 May 2012 09:04 Go to previous messageGo to next message
Eclipse UserFriend
Attached are the build.xml and the main starting class

I've modified them slightly from the ones I actually use to remove any
possible reference to stuff I do for work, so there might be some typos
in there.

It should all be fairly obvious, let me know if you have questions.

In the build I'm currently only packaging for Win32/64. Its obvious and
easy to expand to all SWT platforms.

On 5/11/12 5:26 PM, Jesse Osiecki wrote:
> I'm messing with that code given in the error trying to get it to
> chainload my program. Two questions.
>
> 1) What does your ant build script look like?
>
> 2)I have completely forgotten and will probably ask later 8)


package com.andi;

import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Properties;

public class Main {
private static final String LAUNCH_CLASS = "com.andi.TheRealMainClass";

public static void main(final String[] args) {
final String osArch = System.getProperty("os.arch");
final String osName = System.getProperty("os.name").toUpperCase();

final boolean is32bit = !osArch.contains("64");
final boolean isWindows = osName.contains("WINDOWS");
final boolean isLinux = osName.contains("LINUX") || osName.contains("NIX");
final boolean isMac = osName.contains("MAC");

String path = "";
if (isWindows)
path = "win";
else if (isLinux)
path = "gtk";
else if (isMac)
path = "mac";
if (is32bit)
path = path + "32";
else
path = path + "64";
System.out.println("Selected SWT classpath platform: " + path);
final ClassLoader parent = Main.class.getClassLoader();

final ArrayList<URL> urls = new ArrayList<URL>();
try {
final InputStream stream = parent.getResourceAsStream("libjars.properties");
final Properties properties = new Properties();
properties.load(stream);
stream.close();
String libs = (String) properties.get("contents");
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + aLib + "!/"));
}
libs = (String) properties.get("contents." + path);
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + path + "/" + aLib + "!/"));
}
} catch (final Throwable e1) {
}

try {
if (urls.size() > 0) {
final Method m1 = parent.getClass().getDeclaredMethod("addURL", URL.class);
m1.setAccessible(true);
for (final URL url : urls) {
m1.invoke(parent, url);
}
for (final URL url : ((URLClassLoader) parent).getURLs()) {
System.out.println(url);
}
}
final Class<?> class1 = parent.loadClass(LAUNCH_CLASS);
final Method method = class1.getMethod("launch", String[].class);
final Object[] methodArgs = new Object[] { args };
method.invoke(null, methodArgs);
} catch (final Throwable e) {
e.printStackTrace();
}
}

}
  • Attachment: build.xml
    (Size: 2.23KB, Downloaded 175 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 185 times)
Re: Trouble running code on Windows [message #871593 is a reply to message #871311] Mon, 14 May 2012 09:04 Go to previous messageGo to next message
Eclipse UserFriend
Attached are the build.xml and the main starting class

I've modified them slightly from the ones I actually use to remove any
possible reference to stuff I do for work, so there might be some typos
in there.

It should all be fairly obvious, let me know if you have questions.

In the build I'm currently only packaging for Win32/64. Its obvious and
easy to expand to all SWT platforms.

On 5/11/12 5:26 PM, Jesse Osiecki wrote:
> I'm messing with that code given in the error trying to get it to
> chainload my program. Two questions.
>
> 1) What does your ant build script look like?
>
> 2)I have completely forgotten and will probably ask later 8)


package com.andi;

import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Properties;

public class Main {
private static final String LAUNCH_CLASS = "com.andi.TheRealMainClass";

public static void main(final String[] args) {
final String osArch = System.getProperty("os.arch");
final String osName = System.getProperty("os.name").toUpperCase();

final boolean is32bit = !osArch.contains("64");
final boolean isWindows = osName.contains("WINDOWS");
final boolean isLinux = osName.contains("LINUX") || osName.contains("NIX");
final boolean isMac = osName.contains("MAC");

String path = "";
if (isWindows)
path = "win";
else if (isLinux)
path = "gtk";
else if (isMac)
path = "mac";
if (is32bit)
path = path + "32";
else
path = path + "64";
System.out.println("Selected SWT classpath platform: " + path);
final ClassLoader parent = Main.class.getClassLoader();

final ArrayList<URL> urls = new ArrayList<URL>();
try {
final InputStream stream = parent.getResourceAsStream("libjars.properties");
final Properties properties = new Properties();
properties.load(stream);
stream.close();
String libs = (String) properties.get("contents");
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + aLib + "!/"));
}
libs = (String) properties.get("contents." + path);
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + path + "/" + aLib + "!/"));
}
} catch (final Throwable e1) {
}

try {
if (urls.size() > 0) {
final Method m1 = parent.getClass().getDeclaredMethod("addURL", URL.class);
m1.setAccessible(true);
for (final URL url : urls) {
m1.invoke(parent, url);
}
for (final URL url : ((URLClassLoader) parent).getURLs()) {
System.out.println(url);
}
}
final Class<?> class1 = parent.loadClass(LAUNCH_CLASS);
final Method method = class1.getMethod("launch", String[].class);
final Object[] methodArgs = new Object[] { args };
method.invoke(null, methodArgs);
} catch (final Throwable e) {
e.printStackTrace();
}
}

}
  • Attachment: build.xml
    (Size: 2.23KB, Downloaded 176 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 180 times)
Re: Trouble running code on Windows [message #871595 is a reply to message #871311] Mon, 14 May 2012 09:04 Go to previous messageGo to next message
Eclipse UserFriend
Attached are the build.xml and the main starting class

I've modified them slightly from the ones I actually use to remove any
possible reference to stuff I do for work, so there might be some typos
in there.

It should all be fairly obvious, let me know if you have questions.

In the build I'm currently only packaging for Win32/64. Its obvious and
easy to expand to all SWT platforms.

On 5/11/12 5:26 PM, Jesse Osiecki wrote:
> I'm messing with that code given in the error trying to get it to
> chainload my program. Two questions.
>
> 1) What does your ant build script look like?
>
> 2)I have completely forgotten and will probably ask later 8)


package com.andi;

import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Properties;

public class Main {
private static final String LAUNCH_CLASS = "com.andi.TheRealMainClass";

public static void main(final String[] args) {
final String osArch = System.getProperty("os.arch");
final String osName = System.getProperty("os.name").toUpperCase();

final boolean is32bit = !osArch.contains("64");
final boolean isWindows = osName.contains("WINDOWS");
final boolean isLinux = osName.contains("LINUX") || osName.contains("NIX");
final boolean isMac = osName.contains("MAC");

String path = "";
if (isWindows)
path = "win";
else if (isLinux)
path = "gtk";
else if (isMac)
path = "mac";
if (is32bit)
path = path + "32";
else
path = path + "64";
System.out.println("Selected SWT classpath platform: " + path);
final ClassLoader parent = Main.class.getClassLoader();

final ArrayList<URL> urls = new ArrayList<URL>();
try {
final InputStream stream = parent.getResourceAsStream("libjars.properties");
final Properties properties = new Properties();
properties.load(stream);
stream.close();
String libs = (String) properties.get("contents");
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + aLib + "!/"));
}
libs = (String) properties.get("contents." + path);
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + path + "/" + aLib + "!/"));
}
} catch (final Throwable e1) {
}

try {
if (urls.size() > 0) {
final Method m1 = parent.getClass().getDeclaredMethod("addURL", URL.class);
m1.setAccessible(true);
for (final URL url : urls) {
m1.invoke(parent, url);
}
for (final URL url : ((URLClassLoader) parent).getURLs()) {
System.out.println(url);
}
}
final Class<?> class1 = parent.loadClass(LAUNCH_CLASS);
final Method method = class1.getMethod("launch", String[].class);
final Object[] methodArgs = new Object[] { args };
method.invoke(null, methodArgs);
} catch (final Throwable e) {
e.printStackTrace();
}
}

}
  • Attachment: build.xml
    (Size: 2.23KB, Downloaded 157 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 196 times)
Re: Trouble running code on Windows [message #871598 is a reply to message #871311] Mon, 14 May 2012 09:04 Go to previous messageGo to next message
Eclipse UserFriend
Attached are the build.xml and the main starting class

I've modified them slightly from the ones I actually use to remove any
possible reference to stuff I do for work, so there might be some typos
in there.

It should all be fairly obvious, let me know if you have questions.

In the build I'm currently only packaging for Win32/64. Its obvious and
easy to expand to all SWT platforms.

On 5/11/12 5:26 PM, Jesse Osiecki wrote:
> I'm messing with that code given in the error trying to get it to
> chainload my program. Two questions.
>
> 1) What does your ant build script look like?
>
> 2)I have completely forgotten and will probably ask later 8)


package com.andi;

import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Properties;

public class Main {
private static final String LAUNCH_CLASS = "com.andi.TheRealMainClass";

public static void main(final String[] args) {
final String osArch = System.getProperty("os.arch");
final String osName = System.getProperty("os.name").toUpperCase();

final boolean is32bit = !osArch.contains("64");
final boolean isWindows = osName.contains("WINDOWS");
final boolean isLinux = osName.contains("LINUX") || osName.contains("NIX");
final boolean isMac = osName.contains("MAC");

String path = "";
if (isWindows)
path = "win";
else if (isLinux)
path = "gtk";
else if (isMac)
path = "mac";
if (is32bit)
path = path + "32";
else
path = path + "64";
System.out.println("Selected SWT classpath platform: " + path);
final ClassLoader parent = Main.class.getClassLoader();

final ArrayList<URL> urls = new ArrayList<URL>();
try {
final InputStream stream = parent.getResourceAsStream("libjars.properties");
final Properties properties = new Properties();
properties.load(stream);
stream.close();
String libs = (String) properties.get("contents");
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + aLib + "!/"));
}
libs = (String) properties.get("contents." + path);
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + path + "/" + aLib + "!/"));
}
} catch (final Throwable e1) {
}

try {
if (urls.size() > 0) {
final Method m1 = parent.getClass().getDeclaredMethod("addURL", URL.class);
m1.setAccessible(true);
for (final URL url : urls) {
m1.invoke(parent, url);
}
for (final URL url : ((URLClassLoader) parent).getURLs()) {
System.out.println(url);
}
}
final Class<?> class1 = parent.loadClass(LAUNCH_CLASS);
final Method method = class1.getMethod("launch", String[].class);
final Object[] methodArgs = new Object[] { args };
method.invoke(null, methodArgs);
} catch (final Throwable e) {
e.printStackTrace();
}
}

}
  • Attachment: build.xml
    (Size: 2.23KB, Downloaded 181 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 166 times)
Re: Trouble running code on Windows [message #871599 is a reply to message #871311] Mon, 14 May 2012 09:04 Go to previous messageGo to next message
Eclipse UserFriend
Attached are the build.xml and the main starting class

I've modified them slightly from the ones I actually use to remove any
possible reference to stuff I do for work, so there might be some typos
in there.

It should all be fairly obvious, let me know if you have questions.

In the build I'm currently only packaging for Win32/64. Its obvious and
easy to expand to all SWT platforms.

On 5/11/12 5:26 PM, Jesse Osiecki wrote:
> I'm messing with that code given in the error trying to get it to
> chainload my program. Two questions.
>
> 1) What does your ant build script look like?
>
> 2)I have completely forgotten and will probably ask later 8)


package com.andi;

import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Properties;

public class Main {
private static final String LAUNCH_CLASS = "com.andi.TheRealMainClass";

public static void main(final String[] args) {
final String osArch = System.getProperty("os.arch");
final String osName = System.getProperty("os.name").toUpperCase();

final boolean is32bit = !osArch.contains("64");
final boolean isWindows = osName.contains("WINDOWS");
final boolean isLinux = osName.contains("LINUX") || osName.contains("NIX");
final boolean isMac = osName.contains("MAC");

String path = "";
if (isWindows)
path = "win";
else if (isLinux)
path = "gtk";
else if (isMac)
path = "mac";
if (is32bit)
path = path + "32";
else
path = path + "64";
System.out.println("Selected SWT classpath platform: " + path);
final ClassLoader parent = Main.class.getClassLoader();

final ArrayList<URL> urls = new ArrayList<URL>();
try {
final InputStream stream = parent.getResourceAsStream("libjars.properties");
final Properties properties = new Properties();
properties.load(stream);
stream.close();
String libs = (String) properties.get("contents");
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + aLib + "!/"));
}
libs = (String) properties.get("contents." + path);
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + path + "/" + aLib + "!/"));
}
} catch (final Throwable e1) {
}

try {
if (urls.size() > 0) {
final Method m1 = parent.getClass().getDeclaredMethod("addURL", URL.class);
m1.setAccessible(true);
for (final URL url : urls) {
m1.invoke(parent, url);
}
for (final URL url : ((URLClassLoader) parent).getURLs()) {
System.out.println(url);
}
}
final Class<?> class1 = parent.loadClass(LAUNCH_CLASS);
final Method method = class1.getMethod("launch", String[].class);
final Object[] methodArgs = new Object[] { args };
method.invoke(null, methodArgs);
} catch (final Throwable e) {
e.printStackTrace();
}
}

}
  • Attachment: build.xml
    (Size: 2.23KB, Downloaded 186 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 300 times)
Re: Trouble running code on Windows [message #871601 is a reply to message #871311] Mon, 14 May 2012 09:04 Go to previous messageGo to next message
Eclipse UserFriend
Attached are the build.xml and the main starting class

I've modified them slightly from the ones I actually use to remove any
possible reference to stuff I do for work, so there might be some typos
in there.

It should all be fairly obvious, let me know if you have questions.

In the build I'm currently only packaging for Win32/64. Its obvious and
easy to expand to all SWT platforms.

On 5/11/12 5:26 PM, Jesse Osiecki wrote:
> I'm messing with that code given in the error trying to get it to
> chainload my program. Two questions.
>
> 1) What does your ant build script look like?
>
> 2)I have completely forgotten and will probably ask later 8)


package com.andi;

import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Properties;

public class Main {
private static final String LAUNCH_CLASS = "com.andi.TheRealMainClass";

public static void main(final String[] args) {
final String osArch = System.getProperty("os.arch");
final String osName = System.getProperty("os.name").toUpperCase();

final boolean is32bit = !osArch.contains("64");
final boolean isWindows = osName.contains("WINDOWS");
final boolean isLinux = osName.contains("LINUX") || osName.contains("NIX");
final boolean isMac = osName.contains("MAC");

String path = "";
if (isWindows)
path = "win";
else if (isLinux)
path = "gtk";
else if (isMac)
path = "mac";
if (is32bit)
path = path + "32";
else
path = path + "64";
System.out.println("Selected SWT classpath platform: " + path);
final ClassLoader parent = Main.class.getClassLoader();

final ArrayList<URL> urls = new ArrayList<URL>();
try {
final InputStream stream = parent.getResourceAsStream("libjars.properties");
final Properties properties = new Properties();
properties.load(stream);
stream.close();
String libs = (String) properties.get("contents");
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + aLib + "!/"));
}
libs = (String) properties.get("contents." + path);
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + path + "/" + aLib + "!/"));
}
} catch (final Throwable e1) {
}

try {
if (urls.size() > 0) {
final Method m1 = parent.getClass().getDeclaredMethod("addURL", URL.class);
m1.setAccessible(true);
for (final URL url : urls) {
m1.invoke(parent, url);
}
for (final URL url : ((URLClassLoader) parent).getURLs()) {
System.out.println(url);
}
}
final Class<?> class1 = parent.loadClass(LAUNCH_CLASS);
final Method method = class1.getMethod("launch", String[].class);
final Object[] methodArgs = new Object[] { args };
method.invoke(null, methodArgs);
} catch (final Throwable e) {
e.printStackTrace();
}
}

}
  • Attachment: build.xml
    (Size: 2.23KB, Downloaded 176 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 172 times)
Re: Trouble running code on Windows [message #871603 is a reply to message #871311] Mon, 14 May 2012 09:04 Go to previous messageGo to next message
Eclipse UserFriend
Attached are the build.xml and the main starting class

I've modified them slightly from the ones I actually use to remove any
possible reference to stuff I do for work, so there might be some typos
in there.

It should all be fairly obvious, let me know if you have questions.

In the build I'm currently only packaging for Win32/64. Its obvious and
easy to expand to all SWT platforms.

On 5/11/12 5:26 PM, Jesse Osiecki wrote:
> I'm messing with that code given in the error trying to get it to
> chainload my program. Two questions.
>
> 1) What does your ant build script look like?
>
> 2)I have completely forgotten and will probably ask later 8)


package com.andi;

import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Properties;

public class Main {
private static final String LAUNCH_CLASS = "com.andi.TheRealMainClass";

public static void main(final String[] args) {
final String osArch = System.getProperty("os.arch");
final String osName = System.getProperty("os.name").toUpperCase();

final boolean is32bit = !osArch.contains("64");
final boolean isWindows = osName.contains("WINDOWS");
final boolean isLinux = osName.contains("LINUX") || osName.contains("NIX");
final boolean isMac = osName.contains("MAC");

String path = "";
if (isWindows)
path = "win";
else if (isLinux)
path = "gtk";
else if (isMac)
path = "mac";
if (is32bit)
path = path + "32";
else
path = path + "64";
System.out.println("Selected SWT classpath platform: " + path);
final ClassLoader parent = Main.class.getClassLoader();

final ArrayList<URL> urls = new ArrayList<URL>();
try {
final InputStream stream = parent.getResourceAsStream("libjars.properties");
final Properties properties = new Properties();
properties.load(stream);
stream.close();
String libs = (String) properties.get("contents");
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + aLib + "!/"));
}
libs = (String) properties.get("contents." + path);
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + path + "/" + aLib + "!/"));
}
} catch (final Throwable e1) {
}

try {
if (urls.size() > 0) {
final Method m1 = parent.getClass().getDeclaredMethod("addURL", URL.class);
m1.setAccessible(true);
for (final URL url : urls) {
m1.invoke(parent, url);
}
for (final URL url : ((URLClassLoader) parent).getURLs()) {
System.out.println(url);
}
}
final Class<?> class1 = parent.loadClass(LAUNCH_CLASS);
final Method method = class1.getMethod("launch", String[].class);
final Object[] methodArgs = new Object[] { args };
method.invoke(null, methodArgs);
} catch (final Throwable e) {
e.printStackTrace();
}
}

}
  • Attachment: build.xml
    (Size: 2.23KB, Downloaded 238 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 196 times)
Re: Trouble running code on Windows [message #871606 is a reply to message #871311] Mon, 14 May 2012 09:04 Go to previous messageGo to next message
Eclipse UserFriend
Attached are the build.xml and the main starting class

I've modified them slightly from the ones I actually use to remove any
possible reference to stuff I do for work, so there might be some typos
in there.

It should all be fairly obvious, let me know if you have questions.

In the build I'm currently only packaging for Win32/64. Its obvious and
easy to expand to all SWT platforms.

On 5/11/12 5:26 PM, Jesse Osiecki wrote:
> I'm messing with that code given in the error trying to get it to
> chainload my program. Two questions.
>
> 1) What does your ant build script look like?
>
> 2)I have completely forgotten and will probably ask later 8)


package com.andi;

import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Properties;

public class Main {
private static final String LAUNCH_CLASS = "com.andi.TheRealMainClass";

public static void main(final String[] args) {
final String osArch = System.getProperty("os.arch");
final String osName = System.getProperty("os.name").toUpperCase();

final boolean is32bit = !osArch.contains("64");
final boolean isWindows = osName.contains("WINDOWS");
final boolean isLinux = osName.contains("LINUX") || osName.contains("NIX");
final boolean isMac = osName.contains("MAC");

String path = "";
if (isWindows)
path = "win";
else if (isLinux)
path = "gtk";
else if (isMac)
path = "mac";
if (is32bit)
path = path + "32";
else
path = path + "64";
System.out.println("Selected SWT classpath platform: " + path);
final ClassLoader parent = Main.class.getClassLoader();

final ArrayList<URL> urls = new ArrayList<URL>();
try {
final InputStream stream = parent.getResourceAsStream("libjars.properties");
final Properties properties = new Properties();
properties.load(stream);
stream.close();
String libs = (String) properties.get("contents");
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + aLib + "!/"));
}
libs = (String) properties.get("contents." + path);
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + path + "/" + aLib + "!/"));
}
} catch (final Throwable e1) {
}

try {
if (urls.size() > 0) {
final Method m1 = parent.getClass().getDeclaredMethod("addURL", URL.class);
m1.setAccessible(true);
for (final URL url : urls) {
m1.invoke(parent, url);
}
for (final URL url : ((URLClassLoader) parent).getURLs()) {
System.out.println(url);
}
}
final Class<?> class1 = parent.loadClass(LAUNCH_CLASS);
final Method method = class1.getMethod("launch", String[].class);
final Object[] methodArgs = new Object[] { args };
method.invoke(null, methodArgs);
} catch (final Throwable e) {
e.printStackTrace();
}
}

}
  • Attachment: build.xml
    (Size: 2.23KB, Downloaded 209 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 178 times)
Re: Trouble running code on Windows [message #871608 is a reply to message #871311] Mon, 14 May 2012 09:04 Go to previous messageGo to next message
Eclipse UserFriend
Attached are the build.xml and the main starting class

I've modified them slightly from the ones I actually use to remove any
possible reference to stuff I do for work, so there might be some typos
in there.

It should all be fairly obvious, let me know if you have questions.

In the build I'm currently only packaging for Win32/64. Its obvious and
easy to expand to all SWT platforms.

On 5/11/12 5:26 PM, Jesse Osiecki wrote:
> I'm messing with that code given in the error trying to get it to
> chainload my program. Two questions.
>
> 1) What does your ant build script look like?
>
> 2)I have completely forgotten and will probably ask later 8)


package com.andi;

import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Properties;

public class Main {
private static final String LAUNCH_CLASS = "com.andi.TheRealMainClass";

public static void main(final String[] args) {
final String osArch = System.getProperty("os.arch");
final String osName = System.getProperty("os.name").toUpperCase();

final boolean is32bit = !osArch.contains("64");
final boolean isWindows = osName.contains("WINDOWS");
final boolean isLinux = osName.contains("LINUX") || osName.contains("NIX");
final boolean isMac = osName.contains("MAC");

String path = "";
if (isWindows)
path = "win";
else if (isLinux)
path = "gtk";
else if (isMac)
path = "mac";
if (is32bit)
path = path + "32";
else
path = path + "64";
System.out.println("Selected SWT classpath platform: " + path);
final ClassLoader parent = Main.class.getClassLoader();

final ArrayList<URL> urls = new ArrayList<URL>();
try {
final InputStream stream = parent.getResourceAsStream("libjars.properties");
final Properties properties = new Properties();
properties.load(stream);
stream.close();
String libs = (String) properties.get("contents");
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + aLib + "!/"));
}
libs = (String) properties.get("contents." + path);
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + path + "/" + aLib + "!/"));
}
} catch (final Throwable e1) {
}

try {
if (urls.size() > 0) {
final Method m1 = parent.getClass().getDeclaredMethod("addURL", URL.class);
m1.setAccessible(true);
for (final URL url : urls) {
m1.invoke(parent, url);
}
for (final URL url : ((URLClassLoader) parent).getURLs()) {
System.out.println(url);
}
}
final Class<?> class1 = parent.loadClass(LAUNCH_CLASS);
final Method method = class1.getMethod("launch", String[].class);
final Object[] methodArgs = new Object[] { args };
method.invoke(null, methodArgs);
} catch (final Throwable e) {
e.printStackTrace();
}
}

}
  • Attachment: build.xml
    (Size: 2.23KB, Downloaded 177 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 172 times)
Re: Trouble running code on Windows [message #871611 is a reply to message #871311] Mon, 14 May 2012 09:04 Go to previous messageGo to next message
Eclipse UserFriend
Attached are the build.xml and the main starting class

I've modified them slightly from the ones I actually use to remove any
possible reference to stuff I do for work, so there might be some typos
in there.

It should all be fairly obvious, let me know if you have questions.

In the build I'm currently only packaging for Win32/64. Its obvious and
easy to expand to all SWT platforms.

On 5/11/12 5:26 PM, Jesse Osiecki wrote:
> I'm messing with that code given in the error trying to get it to
> chainload my program. Two questions.
>
> 1) What does your ant build script look like?
>
> 2)I have completely forgotten and will probably ask later 8)


package com.andi;

import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Properties;

public class Main {
private static final String LAUNCH_CLASS = "com.andi.TheRealMainClass";

public static void main(final String[] args) {
final String osArch = System.getProperty("os.arch");
final String osName = System.getProperty("os.name").toUpperCase();

final boolean is32bit = !osArch.contains("64");
final boolean isWindows = osName.contains("WINDOWS");
final boolean isLinux = osName.contains("LINUX") || osName.contains("NIX");
final boolean isMac = osName.contains("MAC");

String path = "";
if (isWindows)
path = "win";
else if (isLinux)
path = "gtk";
else if (isMac)
path = "mac";
if (is32bit)
path = path + "32";
else
path = path + "64";
System.out.println("Selected SWT classpath platform: " + path);
final ClassLoader parent = Main.class.getClassLoader();

final ArrayList<URL> urls = new ArrayList<URL>();
try {
final InputStream stream = parent.getResourceAsStream("libjars.properties");
final Properties properties = new Properties();
properties.load(stream);
stream.close();
String libs = (String) properties.get("contents");
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + aLib + "!/"));
}
libs = (String) properties.get("contents." + path);
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + path + "/" + aLib + "!/"));
}
} catch (final Throwable e1) {
}

try {
if (urls.size() > 0) {
final Method m1 = parent.getClass().getDeclaredMethod("addURL", URL.class);
m1.setAccessible(true);
for (final URL url : urls) {
m1.invoke(parent, url);
}
for (final URL url : ((URLClassLoader) parent).getURLs()) {
System.out.println(url);
}
}
final Class<?> class1 = parent.loadClass(LAUNCH_CLASS);
final Method method = class1.getMethod("launch", String[].class);
final Object[] methodArgs = new Object[] { args };
method.invoke(null, methodArgs);
} catch (final Throwable e) {
e.printStackTrace();
}
}

}
  • Attachment: build.xml
    (Size: 2.23KB, Downloaded 229 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 193 times)
Re: Trouble running code on Windows [message #871616 is a reply to message #871311] Mon, 14 May 2012 09:04 Go to previous messageGo to next message
Eclipse UserFriend
Attached are the build.xml and the main starting class

I've modified them slightly from the ones I actually use to remove any
possible reference to stuff I do for work, so there might be some typos
in there.

It should all be fairly obvious, let me know if you have questions.

In the build I'm currently only packaging for Win32/64. Its obvious and
easy to expand to all SWT platforms.

On 5/11/12 5:26 PM, Jesse Osiecki wrote:
> I'm messing with that code given in the error trying to get it to
> chainload my program. Two questions.
>
> 1) What does your ant build script look like?
>
> 2)I have completely forgotten and will probably ask later 8)


package com.andi;

import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Properties;

public class Main {
private static final String LAUNCH_CLASS = "com.andi.TheRealMainClass";

public static void main(final String[] args) {
final String osArch = System.getProperty("os.arch");
final String osName = System.getProperty("os.name").toUpperCase();

final boolean is32bit = !osArch.contains("64");
final boolean isWindows = osName.contains("WINDOWS");
final boolean isLinux = osName.contains("LINUX") || osName.contains("NIX");
final boolean isMac = osName.contains("MAC");

String path = "";
if (isWindows)
path = "win";
else if (isLinux)
path = "gtk";
else if (isMac)
path = "mac";
if (is32bit)
path = path + "32";
else
path = path + "64";
System.out.println("Selected SWT classpath platform: " + path);
final ClassLoader parent = Main.class.getClassLoader();

final ArrayList<URL> urls = new ArrayList<URL>();
try {
final InputStream stream = parent.getResourceAsStream("libjars.properties");
final Properties properties = new Properties();
properties.load(stream);
stream.close();
String libs = (String) properties.get("contents");
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + aLib + "!/"));
}
libs = (String) properties.get("contents." + path);
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + path + "/" + aLib + "!/"));
}
} catch (final Throwable e1) {
}

try {
if (urls.size() > 0) {
final Method m1 = parent.getClass().getDeclaredMethod("addURL", URL.class);
m1.setAccessible(true);
for (final URL url : urls) {
m1.invoke(parent, url);
}
for (final URL url : ((URLClassLoader) parent).getURLs()) {
System.out.println(url);
}
}
final Class<?> class1 = parent.loadClass(LAUNCH_CLASS);
final Method method = class1.getMethod("launch", String[].class);
final Object[] methodArgs = new Object[] { args };
method.invoke(null, methodArgs);
} catch (final Throwable e) {
e.printStackTrace();
}
}

}
  • Attachment: build.xml
    (Size: 2.23KB, Downloaded 191 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 233 times)
Re: Trouble running code on Windows [message #871617 is a reply to message #871311] Mon, 14 May 2012 09:04 Go to previous messageGo to next message
Eclipse UserFriend
Attached are the build.xml and the main starting class

I've modified them slightly from the ones I actually use to remove any
possible reference to stuff I do for work, so there might be some typos
in there.

It should all be fairly obvious, let me know if you have questions.

In the build I'm currently only packaging for Win32/64. Its obvious and
easy to expand to all SWT platforms.

On 5/11/12 5:26 PM, Jesse Osiecki wrote:
> I'm messing with that code given in the error trying to get it to
> chainload my program. Two questions.
>
> 1) What does your ant build script look like?
>
> 2)I have completely forgotten and will probably ask later 8)


package com.andi;

import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Properties;

public class Main {
private static final String LAUNCH_CLASS = "com.andi.TheRealMainClass";

public static void main(final String[] args) {
final String osArch = System.getProperty("os.arch");
final String osName = System.getProperty("os.name").toUpperCase();

final boolean is32bit = !osArch.contains("64");
final boolean isWindows = osName.contains("WINDOWS");
final boolean isLinux = osName.contains("LINUX") || osName.contains("NIX");
final boolean isMac = osName.contains("MAC");

String path = "";
if (isWindows)
path = "win";
else if (isLinux)
path = "gtk";
else if (isMac)
path = "mac";
if (is32bit)
path = path + "32";
else
path = path + "64";
System.out.println("Selected SWT classpath platform: " + path);
final ClassLoader parent = Main.class.getClassLoader();

final ArrayList<URL> urls = new ArrayList<URL>();
try {
final InputStream stream = parent.getResourceAsStream("libjars.properties");
final Properties properties = new Properties();
properties.load(stream);
stream.close();
String libs = (String) properties.get("contents");
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + aLib + "!/"));
}
libs = (String) properties.get("contents." + path);
for (final String aLib : libs.split(";")) {
urls.add(new URL("jar:rsrc:lib/" + path + "/" + aLib + "!/"));
}
} catch (final Throwable e1) {
}

try {
if (urls.size() > 0) {
final Method m1 = parent.getClass().getDeclaredMethod("addURL", URL.class);
m1.setAccessible(true);
for (final URL url : urls) {
m1.invoke(parent, url);
}
for (final URL url : ((URLClassLoader) parent).getURLs()) {
System.out.println(url);
}
}
final Class<?> class1 = parent.loadClass(LAUNCH_CLASS);
final Method method = class1.getMethod("launch", String[].class);
final Object[] methodArgs = new Object[] { args };
method.invoke(null, methodArgs);
} catch (final Throwable e) {
e.printStackTrace();
}
}

}
  • Attachment: build.xml
    (Size: 2.23KB, Downloaded 168 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 174 times)
Re: Trouble running code on Windows [message #872183 is a reply to message #871617] Tue, 15 May 2012 11:51 Go to previous message
Eclipse UserFriend
Thank you!!! I 'm going to try this out tonight. I'll Let you know how it goes.
Previous Topic:SWT equivalent of AWT Component.addNotify()
Next Topic:Java Webstart / SWT doens't work on Ubuntu LTS 12.04 ???
Goto Forum:
  


Current Time: Sun Jul 27 02:06:41 EDT 2025

Powered by FUDForum. Page generated in 0.08864 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top