Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 23:22 Go to next message
Jesse Osiecki is currently offline Jesse OsieckiFriend
Messages: 7
Registered: May 2012
Junior Member
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 14:51 Go to previous messageGo to next message
Aberforth Dumbledore is currently offline Aberforth DumbledoreFriend
Messages: 17
Registered: April 2012
Location: A planet called Earth
Junior Member
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 23:01 Go to previous messageGo to next message
Jesse Osiecki is currently offline Jesse OsieckiFriend
Messages: 7
Registered: May 2012
Junior Member
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 19:23 Go to previous messageGo to next message
Andi Thomas is currently offline Andi ThomasFriend
Messages: 38
Registered: July 2009
Member
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 21:26 Go to previous messageGo to next message
Jesse Osiecki is currently offline Jesse OsieckiFriend
Messages: 7
Registered: May 2012
Junior Member
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 13:04 Go to previous messageGo to next message
Andi Thomas is currently offline Andi ThomasFriend
Messages: 38
Registered: July 2009
Member
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 148 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 173 times)
Re: Trouble running code on Windows [message #871580 is a reply to message #871311] Mon, 14 May 2012 13:04 Go to previous messageGo to next message
Andi Thomas is currently offline Andi ThomasFriend
Messages: 38
Registered: July 2009
Member
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 220 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 152 times)
Re: Trouble running code on Windows [message #871583 is a reply to message #871311] Mon, 14 May 2012 13:04 Go to previous messageGo to next message
Andi Thomas is currently offline Andi ThomasFriend
Messages: 38
Registered: July 2009
Member
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 164 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 195 times)
Re: Trouble running code on Windows [message #871586 is a reply to message #871311] Mon, 14 May 2012 13:04 Go to previous messageGo to next message
Andi Thomas is currently offline Andi ThomasFriend
Messages: 38
Registered: July 2009
Member
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 140 times)
Re: Trouble running code on Windows [message #871587 is a reply to message #871311] Mon, 14 May 2012 13:04 Go to previous messageGo to next message
Andi Thomas is currently offline Andi ThomasFriend
Messages: 38
Registered: July 2009
Member
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 146 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 171 times)
Re: Trouble running code on Windows [message #871589 is a reply to message #871311] Mon, 14 May 2012 13:04 Go to previous messageGo to next message
Andi Thomas is currently offline Andi ThomasFriend
Messages: 38
Registered: July 2009
Member
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 202 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 162 times)
Re: Trouble running code on Windows [message #871591 is a reply to message #871311] Mon, 14 May 2012 13:04 Go to previous messageGo to next message
Andi Thomas is currently offline Andi ThomasFriend
Messages: 38
Registered: July 2009
Member
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 166 times)
Re: Trouble running code on Windows [message #871593 is a reply to message #871311] Mon, 14 May 2012 13:04 Go to previous messageGo to next message
Andi Thomas is currently offline Andi ThomasFriend
Messages: 38
Registered: July 2009
Member
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 153 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 158 times)
Re: Trouble running code on Windows [message #871595 is a reply to message #871311] Mon, 14 May 2012 13:04 Go to previous messageGo to next message
Andi Thomas is currently offline Andi ThomasFriend
Messages: 38
Registered: July 2009
Member
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 135 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 165 times)
Re: Trouble running code on Windows [message #871598 is a reply to message #871311] Mon, 14 May 2012 13:04 Go to previous messageGo to next message
Andi Thomas is currently offline Andi ThomasFriend
Messages: 38
Registered: July 2009
Member
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 160 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 140 times)
Re: Trouble running code on Windows [message #871599 is a reply to message #871311] Mon, 14 May 2012 13:04 Go to previous messageGo to next message
Andi Thomas is currently offline Andi ThomasFriend
Messages: 38
Registered: July 2009
Member
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 161 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 264 times)
Re: Trouble running code on Windows [message #871601 is a reply to message #871311] Mon, 14 May 2012 13:04 Go to previous messageGo to next message
Andi Thomas is currently offline Andi ThomasFriend
Messages: 38
Registered: July 2009
Member
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 155 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 144 times)
Re: Trouble running code on Windows [message #871603 is a reply to message #871311] Mon, 14 May 2012 13:04 Go to previous messageGo to next message
Andi Thomas is currently offline Andi ThomasFriend
Messages: 38
Registered: July 2009
Member
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 217 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 162 times)
Re: Trouble running code on Windows [message #871606 is a reply to message #871311] Mon, 14 May 2012 13:04 Go to previous messageGo to next message
Andi Thomas is currently offline Andi ThomasFriend
Messages: 38
Registered: July 2009
Member
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 146 times)
Re: Trouble running code on Windows [message #871608 is a reply to message #871311] Mon, 14 May 2012 13:04 Go to previous messageGo to next message
Andi Thomas is currently offline Andi ThomasFriend
Messages: 38
Registered: July 2009
Member
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 150 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 149 times)
Re: Trouble running code on Windows [message #871611 is a reply to message #871311] Mon, 14 May 2012 13:04 Go to previous messageGo to next message
Andi Thomas is currently offline Andi ThomasFriend
Messages: 38
Registered: July 2009
Member
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 204 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 170 times)
Re: Trouble running code on Windows [message #871616 is a reply to message #871311] Mon, 14 May 2012 13:04 Go to previous messageGo to next message
Andi Thomas is currently offline Andi ThomasFriend
Messages: 38
Registered: July 2009
Member
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 165 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 204 times)
Re: Trouble running code on Windows [message #871617 is a reply to message #871311] Mon, 14 May 2012 13:04 Go to previous messageGo to next message
Andi Thomas is currently offline Andi ThomasFriend
Messages: 38
Registered: July 2009
Member
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 151 times)
  • Attachment: main.java
    (Size: 2.24KB, Downloaded 150 times)
Re: Trouble running code on Windows [message #872183 is a reply to message #871617] Tue, 15 May 2012 15:51 Go to previous message
Jesse Osiecki is currently offline Jesse OsieckiFriend
Messages: 7
Registered: May 2012
Junior Member
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: Sat Apr 20 06:23:29 GMT 2024

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

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

Back to the top