1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Executing a jar file from another jar file.

Discussion in 'Software Development' started by JoshRod, Apr 14, 2010.

Thread Status:
Not open for further replies.
Advertisement
  1. JoshRod

    JoshRod Thread Starter

    Joined:
    Nov 1, 2009
    Messages:
    125
    I'm currently using an applet to run a jar file named Loader.jar to run another jar file named ERO.jar, which is obfuscated. The loader loads fine, but it does not pop out the GUI as it's supposed to. Here's the HTML part of the loading:

    Code:
    <HTML>  
    <HEAD>  
    <TITLE>Client</TITLE>  
    <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">  
    </HEAD>  
    <BODY>  
    <CENTER>  
    <APPLET NAME = "Client" WIDTH = "500" HEIGHT = "85" ARCHIVE = "Loader.jar" CODE = "loader.class">  
    <PARAM NAME = "java_arguments" value = "-Xmx1024M">  
    </APPLET>  
    </CENTER>  
    </BODY>  
    </HTML> 
    
    When I normally run the ERO jar file, by using a batch file or double clicking it, it pops up a GUI I made to log in to a server. Although, when I run the HTML file to load the Loader.jar file, it runs as it should for the most part, but it won't pop up the GUI as it should. Here's a pic of it at the moment:

    http://img97.imageshack.us/img97/9121/applet.png

    It just stops there, but it won't pop up the GUI. The GUI looks like this:

    http://img243.imageshack.us/img243/2332/loginei.png

    When just by running a jar file normally, it works. But when running a jar file to run another one, it won't.

    loader class (main class):
    http://pastebin.com/3tMnKtt5

    Bot class:
    http://pastebin.com/Wycu6hFK

    ProgressChecker class:
    http://pastebin.com/4mHgvj9a

    PreLoader class:
    http://pastebin.com/pRr0cAs9

    Updated class:
    http://pastebin.com/jw86VvVp

    Unpack class:
    http://pastebin.com/u9Jh2Qak

    Terminate class:
    http://pastebin.com/FwkRQ5rS

    GameFrame class:
    http://pastebin.com/p0phfHjv

    GamePanel class:
    http://pastebin.com/nffxBw3H

    Sorry for the classes being so long and having so many, but I just can't seem to figure out why it won't load the GUI properly. Help is appreciated. Thanks.
     
  2. liquid_vision

    liquid_vision

    Joined:
    Apr 17, 2010
    Messages:
    41
    I'm confused. Your loader class is the main class, and it extends JApplet.

    This loader is contained within a loader jar, which is then used to load another jar.

    In this second jar, what is the main class which starts the program up, and what syntax do you use to launch it?


    Also, in your loader, you have 2 constructors, one default and one overloaded.

    The only difference I can spot between them is that the overloaded one is passed a string array.
    Other than that, it seems identical, and doesn't actually use the string array for anything.

    Is this something that has been overlooked, or have I missed the reason for doing this?

    ---------

    In the section


    1. public final String findCacheDir() {
    2. String[] dir = {
    3. "c:/windows/", "c:/winnt/", "d:/windows/", "d:/winnt/", "e:/windows/", "e:/winnt/",
    4. "f:/windows/", "f:/winnt/", "c:/", "~/", "/tmp/", "", "c:/rscache", "/rscache"
    5. };
    6. String str = "ERcache_file_store_32";
    7. for (int i = 0; i < str.length(); i++) {

    I presume the line

    for (int i = 0; i < str.length(); i++) {

    should read

    for (int i = 0; i < dir.length(); i++) {

    otherwise, you are stepping through each letter of "ERcache_file_store_32" rather than folder names.


    -------


    This section makes very little sense to me. You are opening a socket directly to a zip file, on port 704.


    sock = new Socket("http://elementalregion.com/ERcache/cache.zip", 704); sock.setSoTimeout(1000);
    OutputStream out = sock.getOutputStream();
    InputStream in = sock.getInputStream();
    out.write(len);

    Creating an integer (i) as value -1

    int i = -1;

    You have a while statement which doesn't have a brace at the end, so does nothing...

    while(in.available() <= 0);

    ...and you are reading a zip file 1 integer at a time into a value which contains an integer....

    i = in.read();


    ---------

    In your preloader,you have the line

    Class load = (Class)hash.get(str);

    but the hash table at this stage has not been populated with anything...



    It would be helpful if you could go through the code and comment it so we knew what you are trying to achieve.

    As it stands, it's virtually impossible to know what you are trying to do. It seems like a massively overcomplicated way to go about loading a class from a jar.
     
  3. liquid_vision

    liquid_vision

    Joined:
    Apr 17, 2010
    Messages:
    41
  4. JoshRod

    JoshRod Thread Starter

    Joined:
    Nov 1, 2009
    Messages:
    125
    I've fixed almost everything. Cache loads, no more for loops and whatnot. I changed a lot of the code around so that it does work. Now, I just have one error:

    Code:
    Java Plug-in 1.6.0_20
    Using JRE version 1.6.0_20-b02 Java HotSpot(TM) Client VM
    User home directory = C:\Documents and Settings\Owner
    
    ----------------------------------------------------
    c:   clear console window
    f:   finalize objects on finalization queue
    g:   garbage collect
    h:   display this help message
    l:   dump classloader list
    m:   print memory usage
    o:   trigger logging
    q:   hide console
    r:   reload policy configuration
    s:   dump system and deployment properties
    t:   dump thread list
    v:   dump thread stack
    x:   clear classloader cache
    0-5: set trace level to <n>
    ----------------------------------------------------
    
    security: property package.access value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.
    security: property package.access new value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws
    security: property package.access value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws
    security: property package.access new value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws,com.sun.deploy
    security: property package.access value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws,com.sun.deploy
    security: property package.access new value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws,com.sun.deploy,com.sun.jnlp
    security: property package.definition value null
    security: property package.definition new value com.sun.javaws
    security: property package.definition value com.sun.javaws
    security: property package.definition new value com.sun.javaws,com.sun.deploy
    security: property package.definition value com.sun.javaws,com.sun.deploy
    security: property package.definition new value com.sun.javaws,com.sun.deploy,com.sun.jnlp
    security: property package.access value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws,com.sun.deploy,com.sun.jnlp
    security: property package.access new value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws,com.sun.deploy,com.sun.jnlp,org.mozilla.jss
    security: property package.definition value com.sun.javaws,com.sun.deploy,com.sun.jnlp
    security: property package.definition new value com.sun.javaws,com.sun.deploy,com.sun.jnlp,org.mozilla.jss
    basic: Added progress listener: [email protected]
    basic: Plugin2ClassLoader.addURL parent called for file:/C:/Documents%20and%20Settings/Owner/Desktop/ERClientFiles/Loader/Loader.jar
    network: Cache entry not found [url: file:/C:/Documents%20and%20Settings/Owner/Desktop/ERClientFiles/Loader/Loader.jar, version: null]
    security: Accessing keys and certificate in Mozilla user profile: null
    security: Loading Root CA certificates from C:\Program Files\Java\jre6\lib\security\cacerts
    security: Loaded Root CA certificates from C:\Program Files\Java\jre6\lib\security\cacerts
    security: Loading Deployment certificates from C:\Documents and Settings\Owner\Application Data\Sun\Java\Deployment\security\trusted.certs
    security: Loaded Deployment certificates from C:\Documents and Settings\Owner\Application Data\Sun\Java\Deployment\security\trusted.certs
    security: Loading certificates from Deployment session certificate store
    security: Loaded certificates from Deployment session certificate store
    security: Validate the certificate chain using CertPath API
    security: Obtain certificate collection in Root CA certificate store
    security: Obtain certificate collection in Root CA certificate store
    security: Start to check whether root CA is replaced
    security: The root CA hasnt been replaced
    security: No timestamping info available
    security: Found jurisdiction list file
    security: No need to checking trusted extension for this certificate
    security: The CRL support is disabled
    security: The OCSP support is disabled
    security: This OCSP End Entity validation is disabled
    security: Checking if certificate is in Deployment denied certificate store
    security: Checking if certificate is in Deployment permanent certificate store
    network: Cache entry not found [url: file:/C:/Documents%20and%20Settings/Owner/Desktop/ERClientFiles/Loader/Loader.jar, version: null]
    network: Cache entry not found [url: file:/C:/Documents%20and%20Settings/Owner/Desktop/ERClientFiles/Loader/Loader.jar, version: null]
    security: Loading certificates from Deployment session certificate store
    security: Loaded certificates from Deployment session certificate store
    security: Validate the certificate chain using CertPath API
    security: Obtain certificate collection in Root CA certificate store
    security: Obtain certificate collection in Root CA certificate store
    security: Start to check whether root CA is replaced
    security: The root CA hasnt been replaced
    security: No timestamping info available
    security: Found jurisdiction list file
    security: No need to checking trusted extension for this certificate
    security: The CRL support is disabled
    security: The OCSP support is disabled
    security: This OCSP End Entity validation is disabled
    security: Checking if certificate is in Deployment denied certificate store
    security: Checking if certificate is in Deployment permanent certificate store
    network: Cache entry not found [url: file:/C:/Documents%20and%20Settings/Owner/Desktop/ERClientFiles/Loader/Loader.jar, version: null]
    basic: Plugin2ClassLoader.getPermissions CeilingPolicy allPerms
    basic: Applet loaded.
    basic: Applet resized and added to parent container
    basic: PERF: AppletExecutionRunnable - applet.init() BEGIN ; jvmLaunch dt 1249638 us, pluginInit dt 3813729 us, TotalTime: 5063367 us
    java.lang.ClassNotFoundException: client
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.findSystemClass(Unknown Source)
        at PreLoader.load(PreLoader.java:16)
        at loader.init(loader.java:39)
        at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
    java.lang.ClassNotFoundException: client
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.findSystemClass(Unknown Source)
        at PreLoader.load(PreLoader.java:26)
        at loader.init(loader.java:39)
        at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
    basic: Applet initialized
    basic: Removed progress listener: [email protected]
    basic: Applet made visible
    basic: Starting applet
    basic: completed perf rollup
    basic: Applet started
    basic: Told clients applet is started
    
    Line 39 - Loader Class: Class load = loader.load("client", true);
    Line 16, 26 - PreLoader Class: return super.findSystemClass(str);

    Although, wouldn't it try to find the client class anywhere or no, only in the same directory as the HTML file? The client class is inside the ERclient.jar file. Changed jar files, went from obfuscated (ERO.jar) to non (ERclient.jar). If I specified getFile("ERclient.jar"); and then I declared the method load to load the client class, shouldn't it look in the ERclient.jar file and load it properly?
     
  5. liquid_vision

    liquid_vision

    Joined:
    Apr 17, 2010
    Messages:
    41
    hmmm....

    I take it from your references to windows drive names that you are working on a windows system...

    If so, the problem is that Java doesn't like loading trusted classes from the windows classpath (Ie, %SYSTEMROOT%).

    Solution, you need to put any classes/jar files that you are loading using your loader method somewhere on the Java classpath (your "java home\lib" folder should be ok), not the windows one, or, add the folder your jar files are contained in onto the Java classpath.

    That should solve the problem.

    It could be worthwhile getting a Linux install running if you intend to do much Java development.

    It made my life infinitely easier...
     
  6. JoshRod

    JoshRod Thread Starter

    Joined:
    Nov 1, 2009
    Messages:
    125
    I have Linux on my Laptop and Windows XP on my Desktop, which I am on at the moment. Also, I never used the Windows classpath: %SYSTEMROOT% or any of that sort. I just simply give it a directory to go to, as so:

    "C:\Program Files\Java\jre6\bin\java" or "C:program Files\Java\jdk1.6.0_18\bin\javac"

    I don't use "%CLASSAPTH%" or any of those only because I never wanted to nor knew how to; never took the time to care about how to do it like that. The folder looks as so:

    http://img63.imageshack.us/img63/7990/erclientfolder.png

    Once I go to the Loader file, it looks like this:

    http://img11.imageshack.us/img11/9282/loaderfolder.png

    I still don't know why it doesn't know where the client class is. Doesn't seem right though.
     
  7. liquid_vision

    liquid_vision

    Joined:
    Apr 17, 2010
    Messages:
    41
    so,when you are compiling or running a Java program, you are typing the entire path to java.exe or javac.exe?
     
  8. JoshRod

    JoshRod Thread Starter

    Joined:
    Nov 1, 2009
    Messages:
    125
    Yes, I don't mind it though.
     
  9. liquid_vision

    liquid_vision

    Joined:
    Apr 17, 2010
    Messages:
    41
    erm.......

    The issue here is not whether you mind it or not.

    You are doing it incorrectly.

    You NEED your classpath set up, or how does the JVM know where to find related classes?

    Trusted Jars run from trusted folders. These are defined by the classpath. If you don't have a classpath set up, you do not have a working java install.

    It's nothing to do with preference, it's just how it works!!!!!
     
  10. JoshRod

    JoshRod Thread Starter

    Joined:
    Nov 1, 2009
    Messages:
    125
    Oh... No wonder. Alright, I'll download JRE and JDK all over just so that it works and I'll edit the post to let you know if it works.
     
  11. liquid_vision

    liquid_vision

    Joined:
    Apr 17, 2010
    Messages:
    41
    http://indiapoly.com/books/1256/classpath-and-setting-classpath-windows-xp.html

    Follow that guide, and add the folder where the Jar files you are loading using the loader class are located.

    That will allow them to run as trusted jars.

    Windows is VERY particular about trusted jar files, even though it *will* run some apps without a correctly configured classpath.

    I would VERY strongly suggest you start doing some java dev on linux, as if you don't have it set up correctly, it just wont work at all.
     
  12. liquid_vision

    liquid_vision

    Joined:
    Apr 17, 2010
    Messages:
    41
    There's no need to download the JRE. Just the JDK.

    If you have a seperate JRE and JDK on the one system, your programs will compile with the libraries in the JDK, and will run with those in the JRE.

    The JDK comes with a JRE, and setting up the classpath to point to the JRE's bin and lib folders within the JDK directory itself will make them all run from the same libraries.
     
  13. JoshRod

    JoshRod Thread Starter

    Joined:
    Nov 1, 2009
    Messages:
    125
    I have done some Java work on my laptop. Some classes here and there, but very rarely do I actually use my laptop for programming usage. Only reason is because it only has very limited space; it's a Dell mini '09.
     
  14. liquid_vision

    liquid_vision

    Joined:
    Apr 17, 2010
    Messages:
    41
    The way to know if it's workin properly is to try and run java or javac from the command prompt straight at the root of your C drive.

    If it executes, it works.

    The error you were having was a class not found error.

    In short, it's looking for some class file, but it has no idea where.

    You might well have told the loader where to find the jar you are starting directly, but in order to load another jar/class, it has to know where to find it.

    Java runs within a sandbox, and as such, will only load up libs that are found in particular places (trusted folders).

    If it didn't there would be no way to control what ran and what didn't, and considering that what you are doing is starting up a program from the local machine by first downloading it from a web directory, then running it, you would expect a language that had that level of versitility to be controlled in some way.

    Otherwise, whats to stop any old app running without being checked and doing something dodgy...


    As for the laptop side of things, a mate of mine (very good programmer infact) uses a mini 9 as his main uni development machine.

    Slightly small screen, but not a bad little laptop at all!
     
  15. JoshRod

    JoshRod Thread Starter

    Joined:
    Nov 1, 2009
    Messages:
    125
    Indeed, it is a great laptop. Very easy to use. Only thing bad about mine is the memory; very little of it. When I first got it, the OS took up most of it, which was Ubuntu. Since I still have my Windows based machine, it seems easier to run things since I'm more comfortable with Windows rather than Ubuntu. Used the the CMD rather than the terminal, as well as the commands. But, I shall look into doing more programming on my laptop rather than my Desktop PC. If in fact it becomes much easier than what I am doing now, I might switch over.

    EDIT: Mmm, still didn't work. Setting the classpath for the JDK bin folder was no help. Any other ideas?
     
  16. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/916976

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice