Page 3 of 3 FirstFirst 123
Results 41 to 58 of 58
  1. #41
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: the same old story: java.lang.ClassNotFoundException

    But that's not going to help you?
    You want to access something on the server, so set the server up properly.
    If all you want is to be able to get to the images on the server then a policy file is completely unecessary.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  2. #42
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    Thanks tolls I got that one.
    But I am not at the server yet.
    Have a folder that contains the HTML page with the TAG.
    That folder has a folder with the classes of the applet and the image folder.
    I'd like to see first the applet work from within that HTML page because I would
    like to try some pram stuff first without getting into another level of problems
    which is the server (there I believe to get help of the people who run the server.....).
    So there is a missing step still concerning:
    -Djava.security.policy=applet.policy
    and the policy file which would be something like this?

    grant {
    permission java.security.AllPermission;
    };

    or

    grant {
    permission java.io.FilePermission "<<ALL FILES>>","read";
    };


    BTW the tag that works (for anyone that is following this weird adventure)



    Java Code:
    <HTML>
    <HEAD>
       <TITLE>Applet HTML Page</TITLE>
    </HEAD>
    <BODY>
    
    <!--
    *** GENERATED applet HTML launcher - DO NOT EDIT IN 'BUILD' FOLDER ***
    
    If you need to modify this HTML launcher file (e.g., to add applet parameters), 
    copy it to where your applet class is found in the SRC folder. If you do this, 
    the IDE will use it when you run or debug the applet.
    
    Tip: To exclude an HTML launcher from the JAR file, use exclusion filters in 
    the Packaging page in the Project Properties dialog.
    
    For more information see the online help.
    -->
    
    <H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3>
    
    <P>
    <APPLET codebase="classes" code="slideshowapplet/SlideShowApplet.class" width=700 height=500></APPLET>
    </P>
    
    <HR WIDTH="100%"><FONT SIZE=-1><I>Generated by NetBeans IDE</I></FONT>
    </BODY>
    </HTML>

  3. #43
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    When I start the applet from within the Netbeans platform the applet viewer shows the slide applet in a perfect manner.
    I noted that when netbeans does not find the policy file the applet runs into security problems!

    My lack of understanding is this:
    When I try to start the applet from within the folder using a HTML file with tag (see above)
    that starts a single (applet) page, and the policy file is present at the folder, I still get the security error!
    Can you please help me to understand this?

  4. #44
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: the same old story: java.lang.ClassNotFoundException

    No.
    You don't need a policy file to access the images located where the applet came from.
    Where it came from is (for all intents and purposes) your server.
    You should be able to access the images folder using <image folder name>/<image name>.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #45
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    Than I really do not understand that
    -I get the below error message when starting it from the (above) folder
    -and I do not get it when viewing the applet at netbeans.


    java.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)
    at java.security.AccessControlContext.checkPermission (AccessControlContext.java:374)
    at java.security.AccessController.checkPermission(Acc essController.java:549)
    at java.lang.SecurityManager.checkPermission(Security Manager.java:532)
    at java.lang.SecurityManager.checkPropertyAccess(Secu rityManager.java:1285)
    at java.lang.System.getProperty(System.java:667)
    at slideshowapplet.SlideShowApplet.checkImageFolders( SlideShowApplet.java:261)
    at slideshowapplet.SlideShowApplet.init(SlideShowAppl et.java:88)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Plugin2Manager.java:1639)
    at java.lang.Thread.run(Thread.java:680)

  6. #46
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: the same old story: java.lang.ClassNotFoundException

    Show the code you have in slideshowapplet.SlideShowApplet.checkImageFolders at the moment.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #47
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    Java Code:
    private void checkImageFolders(String currentf) {
            // two image folders has to been checked:
            // 1) the first one called images
            // 2) the second inside iamges called slidshow
            // 3) inside the last one are the picture files for display
            String workingDir = System.getProperty("user.dir");
            String imagefolder = workingDir + File.separator + "images" +
                    File.separator + "slideshow";
            currentimagefolderpath = imagefolder + File.separator + currentf;
            relativepath1 = "images";
            relativepath2 = "images" + File.separator + "slideshow";
            relativepath3 = "images" + File.separator + "slideshow" +
                    File.separator + currentf;
            boolean folderexsistflag = false;
    
            String path = "";
    
            String files = "";
         //   File folder1 = new File(imagefolder); // first image folder "images"
         //   File folder2 = new File(currentimagefolderpath); // second "slideshow"
    
              File folder1 = new File(relativepath1); // first image folder "images"
              File folder2 = new File(relativepath2); // second "slideshow"
              File slideshowpath = new File(relativepath2 + File.separator + currentf);
    
            if (folder1.exists()) {
                System.out.println(" yes file exsist " + folder1);
                folderexsistflag = true;
            }
            else  {
                System.out.println(" no file exsist " + folder1);
                folderexsistflag = false;
            }
            if (folder1.isDirectory())  {
                System.out.println(" yes is folder " + folder1);
                folderexsistflag = true;
            }
            else  {
                System.out.println(" no is not folder " + folder1);
                folderexsistflag = false;
            }
    
    
    
            if (folder2.exists()) {
                System.out.println(" yes file exsist " + folder2);
                folderexsistflag = true;
            }
            else  {
                System.out.println(" no file exsist " + folder2);
                folderexsistflag = false;
            }
    
    
            if (folder2.isDirectory())  {
                System.out.println(" yes is folder " + folder2);
                folderexsistflag = true;
            }
            else  {
                System.out.println(" no is not folder " + folder2);
                folderexsistflag = false;
            }
    
            if (folderexsistflag) {
                doListofImagefiles(slideshowpath); // create the image file list
            }
            else  {
                System.out.println("no folder/ folders present, cannot precede");
            }
    
        }

  8. #48
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    I got a suspicion probably I should only work with these three

    relativepath1 = "images";
    relativepath2 = "images" + File.separator + "slideshow";
    relativepath3 = "images" + File.separator + "slideshow" + File.separator + currentf;

    That is what I do actually: hahahahaha
    sorry!
    Last edited by willemjav; 04-19-2013 at 02:10 PM.

  9. #49
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: the same old story: java.lang.ClassNotFoundException

    Again:
    Java Code:
    String workingDir = System.getProperty("user.dir");
    You are telling the applet to access the client's file system.

    You need to change this (as I've said several times now, and as you yourself have read up on) so it accesses the "server".
    In this case getCodebase is probably good enough.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #50
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    I was not using the string workingDir, but I needed to take it out the code, you are right!

    I only use:
    relativepath1 = "images";
    relativepath2 = "images" + File.separator + "slideshow";
    relativepath3 = "images" + File.separator + "slideshow" + File.separator + currentf;

    But that is still a problem (let me re-think it all)


    Java Code:
    private void checkImageFolders(String currentf) {
            
            relativepath1 = "images";
            relativepath2 = "images" + File.separator + "slideshow";
            relativepath3 = "images" + File.separator + "slideshow" +
                    File.separator + currentf;
            boolean folderexsistflag = false;
    
            String path = "";
    
            String files = "";
         
              File folder1 = new File(relativepath1); // first image folder "images"
              File folder2 = new File(relativepath2); // second "slideshow"
              File slideshowpath = new File(relativepath2 + File.separator + currentf);
    
            if (folder1.exists()) {
                System.out.println(" yes file exsist " + folder1);
                folderexsistflag = true;
            }
            else  {
                System.out.println(" no file exsist " + folder1);
                folderexsistflag = false;
            }
            if (folder1.isDirectory())  {
                System.out.println(" yes is folder " + folder1);
                folderexsistflag = true;
            }
            else  {
                System.out.println(" no is not folder " + folder1);
                folderexsistflag = false;
            }
    
    
    
            if (folder2.exists()) {
                System.out.println(" yes file exsist " + folder2);
                folderexsistflag = true;
            }
            else  {
                System.out.println(" no file exsist " + folder2);
                folderexsistflag = false;
            }
    
    
            if (folder2.isDirectory())  {
                System.out.println(" yes is folder " + folder2);
                folderexsistflag = true;
            }
            else  {
                System.out.println(" no is not folder " + folder2);
                folderexsistflag = false;
            }
    
            if (folderexsistflag) {
                doListofImagefiles(slideshowpath); // create the image file list
            }
            else  {
                System.out.println("no folder/ folders present, cannot precede");
            }
    
        }

  11. #51
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    The string relativepath3 = "images" + File.separator + "slideshow" + File.separator + currentf;
    would still be the client file system?

  12. #52
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: the same old story: java.lang.ClassNotFoundException

    Java Code:
    File folder1 = new File(relativepath1);
    That's accessing the client file system.
    (Sorry picked the wrong bit).
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  13. #53
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    wow, give me some time the think this over
    (so I'll look into getCodebase)

    In a similar program I did 5 years I used:

    URL url = new URL(getDocumentBase(), path);
    image = ImageIO.read(url);
    Last edited by willemjav; 04-19-2013 at 03:17 PM.

  14. #54
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: the same old story: java.lang.ClassNotFoundException

    Or getDocumentBase, which will give you the URL for the HTML page.
    See your post #34, in which you give code examples of using it.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  15. #55
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    Yes I start to understand this. These codebase/ documentbase are special methods that only works for applet to avoid security issues.
    I started the applet as an application and I think I did a good job (at my beginning level) of programming, checking if files/ folders are present
    and looking if the images that are present at the current imagefolder are really images. This all worked just fine as a application and even as an applet shown by the Netbean applet viewer.

    But now as I want to get this going as a real applet, I am in trouble: all this nice looked-up methods that check files/ folders/ and images are not very useful anymore: wow!

    For instance the:

    relativepath3 = new URL(getCodeBase(), "images" + File.separator +
    "slideshow" + File.separator + currentf);

    is, as I believe a path to current image folder. But when I print the string of relativepath3 I get this:

    file:/Users/dragstrawillem/NetBeansProjects/slideshowapplet/build/classes/images/slideshow/calella

    where is calella (a city of the Spanish coast) the current image folder.

    If I would like to use this as a string called "filepath" I need to cut "file:" out right? But I can not do any of the "normal" file stuff like:
    File[] listOfFiles = filepath.listFiles(); or something like this:

    Java Code:
     private boolean checkImageType (File f)  {
            boolean flag = false;
    
                    String fl = ft.getContentType(f);
    
                    String type = fl.split("/")[0];
                    if(type.equals("image"))  {
                            System.out.println("  Is an image:  <" + fl.split("/")[1] + ">   ");
                            return true;
                    }
                    else  {
                            System.out.println("  Is NOT an image");
                            return false;
                    }
        }
    Because the applet would not let me, right!

  16. #56
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    The folder that has the path relativepath3 holds a series of images, could a list the directory of this images and check if they are really images?
    Or will I run into the same trouble?

  17. #57
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    Please tolls bear with me a little more.......

    So I got the getBasecode(); going:

    Java Code:
    try {
                 relativepath3 = new URL(getCodeBase(), "images" + File.separator +
                    "slideshow" + File.separator + currentf);
            } catch (IOException ex) {
                System.out.println("can not read current image folder : " + currentf);
                System.out.println(ex.getMessage());
            }
    Than I would like to do this, and I ask you does this mean applet security trouble again?


    Java Code:
    try {
                    folder = new File(relativepath3.toURI());
                    System.out.println(" try " + folder);
                }
            catch(URISyntaxException e) {
                    folder = new File(relativepath3.getPath());
                    System.out.println(" catch " + folder);
            }
    
            if (folder.exists()) {
                System.out.println(" yes file folder exsists " + folder);
            }
            else  {
                System.out.println(" no file folder " + folder);
            }
    
             doListofImagefiles(folder);
    }
    
    private void doListofImagefiles( File currentfpath)  {
            // storing the present files of the folder
            // into a temporal array for checking
            File[] listOfFiles = currentfpath.listFiles();
            //the array list will contain the correct files
            imagefiles = new ArrayList();
            System.out.println(); System.out.println();
    
            for (int i = 0; i < listOfFiles.length; i++)  {
                String file = listOfFiles[i].getName();
                System.out.print(i + "  > " + file );
                // check for files against folders
                if (listOfFiles[i].isFile()) {
                    //adding the checked correct image files
                      if (checkImageType(listOfFiles[i]))  {
                               imagefiles.add(file);
                      }
                }
            }
            maximages = imagefiles.size();
            System.out.println(" the array list length is: " + maximages);
        }

  18. #58
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: the same old story: java.lang.ClassNotFoundException

    I have it working, thanks for you support!

Page 3 of 3 FirstFirst 123

Similar Threads

  1. java.lang.ClassNotFoundException
    By oim415 in forum New To Java
    Replies: 3
    Last Post: 11-19-2012, 12:01 PM
  2. java.lang.ClassNotFoundException - Issue
    By C.phantasy in forum New To Java
    Replies: 3
    Last Post: 11-05-2012, 05:58 AM
  3. java.lang.ClassNotFoundException
    By djgovins in forum Java Servlet
    Replies: 4
    Last Post: 07-25-2011, 12:54 PM
  4. Replies: 8
    Last Post: 11-04-2010, 02:46 PM
  5. java.lang.ClassNotFoundException
    By ravian in forum New To Java
    Replies: 1
    Last Post: 01-07-2008, 11:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •