views:

1274

answers:

5

Hello.I'd like to make "double-click" cli application but still don't get how. I know I should propably somehow edit manifest but that is all. I googled ofc. but no success. Thanks for any tips. Here is the output from build, run, and manifest:

compile:
Created dir: /home/nick/NetBeansProjects/SemestralWork/dist
Building jar: /home/nick/NetBeansProjects/SemestralWork/dist/SemestralWork.jar
Not copying the libraries.
To run this application from the command line without Ant, try:
java -jar "/home/nick/NetBeansProjects/SemestralWork/dist/SemestralWork.jar"
jar:
BUILD SUCCESSFUL (total time: 1 second)


java -jar /home/nick/NetBeansProjects/SemestralWork/dist/SemestralWork.jar

Exception in thread "main" java.lang.NoClassDefFoundError: semestralwork/Main
Caused by: java.lang.ClassNotFoundException: semestralwork.Main
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:264)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:332)
Could not find the main class: semestralwork.Main. Program will exit.

MY MANIFEST created with build:

Manifest-Version: 1.0

Ant-Version: Apache Ant 1.7.1

Created-By: 14.0-b08 (Sun Microsystems Inc.)

Main-Class: semestralwork.Main

Class-Path: 

X-COMMENT: Main-Class will be added automatically by build
A: 

The default class search path may be the issue. You should try changing directory to the location the jar is and launching with java -jar Semestral.jar. Also you may have misnamed the main class. Please also include your package structure.

whatnick
A: 

Open the JAR file with a ZIP tool (or try less ... if you're on Linux or jar tvf ...). Make sure there is a directory semestralwork in there which contains a file Main.class.

Aaron Digulla
there is just method called "encryption.class" which I call from main method
landscape
That's your problem, then. The class is missing the JAR which is why Java can't find it.
Aaron Digulla
A: 

It's easier to make a .exe from a .jar without netbeans. Here are my suggestions: 1. Use a special application for this(ex: JSmooth, JEXECreator etc) 2. Make a C++ program that starts a JVM (see this tutorial)

+1  A: 

These two lines tell you all you need to know:

Exception in thread "main" java.lang.NoClassDefFoundError: semestralwork/Main
Caused by: java.lang.ClassNotFoundException: semestralwork.Main

And a further clue is dropped by the manifest output:

Main-Class: semestralwork.Main

This means that the JAR file is looking for a package named semestralwork and a class named Main inside it. It fails at this point because it cannot find either the semestralwork package or the Main class.

As you pointed out in your question, the problem is indeed in the manifest file. You can edit this directly in your JAR file if you like, but a better idea would be to do this from Netbeans:

  • Click on `File --> Project Properties (semestralwork)'
  • In the dialog that opens, on the tree on the left select Run
  • Then, on the right, under the field labeled Main class:, enter the fully qualified class name of the class that you want executed when run from the command line.

In your case, as I see from your comment on @Aaron's answer, if your main class is in a file called encryption.java, and it is in the default package (no package), just enter encryption.

Once this is done, do a clean and build, then try running it from the command line again.

HTH

bguiz
A: 

Since I encountered with the same problem, I can clarify the solution a little bit. You must create main Java class outside your method (for example-default_package folder), and then invoke your method(folder), e.g *import your_folder.connected_class;* in that main class. Hopefully I could help someone with the same problem.

Mare