0

I am attempting to put my Java applet into a .Jar so I can sign it, as currently it works locally but throws access denied exceptions when I attempt to run it remotely (it reads other files in the directory).

I created the manifest file correctly when creating the jar and checked it:

Manifest-Version: 1.0
Created-By: 1.6.0_25 (Sun Microsystems Inc.)
Main-Class: netApp

netApp was an applet and runs fine, and it does contain a main method:

import java.awt.*;

import jv.geom.PgElementSet;
import jv.object.PsMainFrame;
import jv.project.PvDisplayIf;
import jv.viewer.PvViewer;
import jv.loader.PgJvxLoader;
import jv.project.PgJvxSrc;
import jv.project.PjProject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.FileReader;
import jv.loader.PjImportModel;
import jv.project.PjProject;
import jv.project.PgGeometry;
import jv.viewer.PvViewer;


import jv.object.PsDebug;

import java.applet.Applet;

public class netApp extends Applet {
    public      Frame               m_frame         = null;
    protected   PvViewer            m_viewer;
    protected   PgGeometry          m_geom;
    protected   netAppProj          myModel;

    public void init() {
        // Create viewer for viewing 3d geometries. References to the applet and frame
        // allow JavaView to decide whether program runs as applet or standalone application,
        // and, in the later case, it allows to use the frame as parent frame.
        m_viewer = new PvViewer(this, m_frame);
        //myModel.addActionListener();
        // Create and load a project which contains the user application. Putting code
        // in a JavaView project allows to reuse the project in other applications.
        myModel = new netAppProj();
        m_viewer.addProject(myModel);
        //myModel.start();
        m_viewer.selectProject(myModel);

        setLayout(new BorderLayout());
        // Get 3d display from viewer and add it to applet
        add((Component)m_viewer.getDisplay(), BorderLayout.CENTER);
        add(m_viewer.getPanel(PvViewer.PROJECT), BorderLayout.EAST);
        m_viewer.showPanel(PvViewer.MATERIAL);


        // Get default display from viewer
        PvDisplayIf disp = m_viewer.getDisplay();
        // Register geometry in display, and make it active.
        // For more advanced applications it is advisable to create a separate project
        // and register geometries in the project via project.addGeometry(geom) calls.
        disp.addGeometry(m_geom);
        disp.selectGeometry(m_geom);
        //disp.addPickListener(myModel);
        /*until here */


    }

    /**
     * Standalone application support. The main() method acts as the applet's
     * entry point when it is run as a standalone application. It is ignored
     * if the applet is run from within an HTML page.
     */
    public static void main(String args[]) {
        netApp app  = new netApp();
        // Create toplevel window of application containing the applet
        Frame frame = new jv.object.PsMainFrame(app, args);
        frame.pack();
        // Store the variable frame inside the applet to indicate
        // that this applet runs as application.
        app.m_frame = frame;
        app.init();
        // In application mode, explicitly call the applet.start() method.
        app.start();
        // Set size of frame when running as application.
        netAppProj myModel = new netAppProj();
        frame.setSize(640, 550);        frame.setBounds(new Rectangle(420, 5, 640, 550));

        frame.setVisible(true);
    }
    /** Print info while initializing applet and viewer. */
    public void paint(Graphics g) {
        g.setColor(Color.blue);
        //g.drawString("Loading Geometry Viewer Version: "+PsConfig.getVersion(), 20, 40);
        g.drawString("Loading Projects .....", 20, 60);
    }

    /**
     * Does clean-up when applet is destroyed by the browser.
     * Here we just close and dispose all our control windows.
     */
    public void destroy()   { m_viewer.destroy(); }

    /** Start viewer, e.g. start animation if requested */
    public void start()     { m_viewer.start(); }

    /** Stop viewer, e.g. stop animation if requested */
    public void stop()      { m_viewer.stop(); }
}

I have tried everything when creating the jar including just doing a:

jar cfm app.jar Manifest.txt *.*

When I try and run the jar from windows explorer or by running:

java -jar app.jar

it fails. with the generic error:

Could not find the main class: netApp. Program will exit.

netApp.class is definitely in the Jar.

Thanks in advance for your help.

user475989
  • 27
  • 1
  • 2
  • 5
  • 1
    what does jar -tf app.jar list? – Liv Apr 26 '11 at 15:40
  • netApp.class is there in the list from 'jar tvf app.jar' along with a load of stuff because I resorted to star.star – user475989 Apr 26 '11 at 15:55
  • can you provide the full dump -- including paths as that is relevant in terms of finding the location of the manifest file. – Liv Apr 26 '11 at 15:56
  • Character limit however here is some of it: C:\Users\Simon\Downloads\files\diagram - edited>jar -tf app.jar META-INF/ META-INF/MANIFEST.MF jars/ jars/browserProps.html jars/contact.html jars/copyright.html jars/functions.php jars/help.html jars/javaview.jar jars/jvLite.jar jars/systemFonts.html jars/vgpapp.jar mainClass Manifest.text Manifest.txt models/ models/net.jvx myApp.html myApp.jar myApp2.jar myApplet.java MyApplication.class MyApplication.java MyJar MyJar.jar MyProject.class MyProject.java MySurface.class MySurface.java nesdfsdt.jvx net.jvx netApp.class netApp.html netApp.java – user475989 Apr 26 '11 at 15:59

1 Answers1

0

Given the error message, it looks like it´s got the manifest correctly, but not the class itself. Run jar tvf app.jar to have a look.

Your jar command looks a little off to me... shouldn´t it be

jar cfm app.jar manifest.txt *.*

?

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • netApp.class is there in the list from 'jar tvf app.jar' along with a load of stuff because I resorted to star.star – user475989 Apr 26 '11 at 15:54
  • You are correct I misquoted my 'jar' command but I had actually run the exact command you gave – user475989 Apr 26 '11 at 15:57
  • 1
    @user475989: What happens if you run `java -classpath app.jar netApp`? – Jon Skeet Apr 26 '11 at 15:59
  • that is a good thing to try -- if the jar structure is correct then it should start the application (or execute the main function in netApp class). if this fails then your jar is corrupted – Liv Apr 26 '11 at 16:02
  • Thank you with this help I've figured it out. One of the files required was itself a jar file. I extracted this and now it works. Turns out you can't have a jar in a jar in a jar... I N C E P T I O N – user475989 Apr 26 '11 at 16:42