我正在尝试将我的Java小程序放入.Jar中以便我可以对其进行签名,因为当前它在本地工作但在我尝试远程运行时会抛出访问被拒绝的异常(它会读取目录中的其他文件)。
我在创建jar时正确创建了清单文件并进行了检查:
Manifest-Version: 1.0
Created-By: 1.6.0_25 (Sun Microsystems Inc.)
Main-Class: netApp
netApp是一个小程序,运行正常,它确实包含一个主要方法:
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(); }
}
我在创建jar时尝试了所有内容,包括执行:
jar cfm app.jar Manifest.txt *.*
当我尝试从Windows资源管理器运行jar或运行:
java -jar app.jar
失败了。与一般错误:
Could not find the main class: netApp. Program will exit.
netApp.class绝对是Jar。
提前感谢您的帮助。
答案 0 :(得分:0)
鉴于错误消息,它看起来是正确的,但不是类本身。运行jar tvf app.jar
来查看。
你的jar
命令对我来说有点不对......不应该是
jar cfm app.jar manifest.txt *.*