This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes trouble constructing new URLClassLoader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "trouble constructing new URLClassLoader" Watch "trouble constructing new URLClassLoader" New topic
Author

trouble constructing new URLClassLoader

David Llewellyn
Ranch Hand

Joined: Feb 01, 2005
Posts: 45
In an applet I'm making I have the following code:

import java.net.*;

public class fileloader extends javax.swing.JApplet {

public fileloader() {
String fileNameString = "http://members.aol.com/davllew/";
URL fileAddressURL = new URL(fileNameString);
URLClassLoader fileClassLoader = new URLClassLoader(fileAddressURL);
}

}

basically I want to load a class from a location in the string fileNameString, but the compiler is giving me an error on the URLClassLoader line. I get the following error:
fileloader.java [8:1] cannot resolve symbol
symbol : constructor URLClassLoader (java.net.URL)
location: class java.net.URLClassLoader

I've asked quite a lot of questions on this forum recently, mainly because I'm pretty new to java, so I hope the questions aren't offensively simple!
cheers
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

The reason you are seeing "cannot resolve symbol" messages is because you are attempting to call a constructor of URLClassLoader which takes a single URL object as its parameter. URLClassLoader doesn't have a constructor like that, hence the confusion. You need to pass it an array of URL objects.

And don't worry - there is no such thing as an "offensively simple" question. Keep posting as many as you need. All questions are valid, because you don't know the answer . Questions only get a frosty response here when they are poorly asked or demanding, neither of which is true of this question.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
David Llewellyn
Ranch Hand

Joined: Feb 01, 2005
Posts: 45
OK, I now have the following code:

import java.net.*;

public class fileloader extends javax.swing.JApplet {

public fileloader() throws Exception{
String fileNameString = "http://members.aol.com/davllew/";
URL[] urlToLoadFrom = new URL[]{new URL(fileNameString)};
URLClassLoader classesToLoad = new URLClassLoader(urlToLoadFrom);
}

}

and I now get the following error:
java.security.AccessControlException: access denied (java.lang.RuntimePermission createClassLoader)

I think this must be because Im using an applet. If it is, how can I get around this (maybe by changing the policy files)?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

Originally posted by David Llewellyn:

I think this must be because Im using an applet. If it is, how can I get around this (maybe by changing the policy files)?


You are correct. Take a look at The Java Tutorial: Applet Security Restrictions for the basics and Advanced Programming for the Java 2 platform: Signed Applets for another option.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
David Llewellyn
Ranch Hand

Joined: Feb 01, 2005
Posts: 45
to get around the security issues ive decided to allow my own URL to be granted all security permissions in a policy file like this:

grant codeBase "http://www.mywebpage.com/myApplets/" {
permission java.security.AllPermission;
};

To make this work I know (or at least I think I know :confused that I have to add the policy file's url to my java.security file, correct?
When i tried loading it with a text editor, It looked like babble.
should I just add the url to the end of the java.security file like this:

policy.url.3=file:/C:/myapplet/mypolicy

?? I tried googleing first, but couldn't find out exactly how to do this.
cheers
 
 
subject: trouble constructing new URLClassLoader
 
Similar Threads
ServletContextListener
java applet problem using super()
error when testing...any help will be appreciated
Refactoring help
file compileproblem