1

I created a jar file for my project , but the following warning appeared , and when double click on it , it does not open

warning: [options] bootstrap class path not set in conjunction with -source 1.6 1 warning

I'm using NetBeans 7.0.1 / Windows 7

ppeterka
  • 20,583
  • 6
  • 63
  • 78
Calm Sea
  • 181
  • 2
  • 4
  • 15

2 Answers2

1

The warning is not necessarily the problem with making it clickable.

To make a JAR executable, you have to specify the 'main' class in the JAR's 'manifest' file, for example:

  Manifest-Version: 1.0
  Main-Class: MyMainClass

You then create the jarfile, specifying the manifest file above. If doing this manually, it's something like:

jar cvfm myapp.jar myManifest *.class

If you created the JAR from NetBeans instead, I expect there's a setting for this:

Updated see Producing executable jar in NetBeans for information on this.

If you don't specify the main class, then the JAR can be used as a library, but it can't be executed directly as a program without using a commandline script to specify which class to run, e.g.

java -cp myjar.jar com.myco.myproj.MyMainClass

which runs Java, putting your jarfile on the classpath (i.e. making all your classes available) and specifies that MyClass is the main class, i.e. the starting point for your application. MyClass must have a main method defined, or this won't work.

Community
  • 1
  • 1
DNA
  • 42,007
  • 12
  • 107
  • 146
  • sorry for my question , but how to specify the 'main' class in the JAR's 'manifest' file??? – Calm Sea Oct 14 '12 at 20:00
  • With its fully qualified name, like `mypackage.myinnerpackage.MyMainClass`. – ppeterka Oct 14 '12 at 20:04
  • @DNA : Thanks any way, but I'm using netbeans , and I do not know from where to change these lines. – Calm Sea Oct 14 '12 at 20:17
  • 1
    Updated my answer - see the answers to [this question](http://stackoverflow.com/questions/602537/producing-executable-jar-in-netbeans) which explain how to do this in NetBeans – DNA Oct 14 '12 at 20:21
  • @DNA : Thanks. one more thing , why the jar file does not open file that I put them in the package , although they opened from the program??? – Calm Sea Oct 14 '12 at 22:14
  • 1
    I'm not certain what you mean - if you mean that you want your application to load a file from within the JAR, then you need to use the [getResource()](http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getResource%28java.lang.String%29) method to load a file from the classpath, rather than just creating a Stream or reader from a File object to load data from the file system. – DNA Oct 14 '12 at 22:27
  • @DAN : one of my packages in my project coantains ".chm file". There is no problem when I opened it from the program, but when I make the jar, the .chm did not open when I clicked the button "help" – Calm Sea Oct 15 '12 at 15:55
0

The warning suggests that there may be a difference between the version of Java that some of your libraries/dependencies are written in and the version you compiled your project with.

In my experience, this warning can usually be ignored. But that is certainly anecdotal.

In the future, the warning can be disabled with the flag -Xlint:-options in "additional compiler options" in Netbeans.

A more official explanation can be found here.

john_science
  • 6,325
  • 6
  • 43
  • 60
  • Does it not open so that you can see the jar/zip contents? Or does it not execute? If you are trying to make it execute you need to make sure the project was compiled in that way. If it was compiled correctly and execution is still a problem, then I think you ran afoul of a problem with one of your dependencies being written for an older JVM than your code was compiled with. (If so, you should give us more information and see if we can determine which library is your problem and if there is a newer version that would suit you.) – john_science Oct 14 '12 at 19:58
  • it does not execute. I run the project without errors , and it works fine. The jar file exists ,but not opening . – Calm Sea Oct 14 '12 at 20:12