.jar not running

0

Create a project in NetBeans with Java JDK 8u131 and JRE 8u131, in the project I use a library called JXL which, as you know, is used to export and import tables Excel

The project works very well when I run it in the same NetBeans, the thing is when I generate the .jar it does not open, I guess for the library I'm using.

For example, in other projects I have used other libraries like jCalendar or Jtatoo and this problem does not generate it.

Does anyone know why this error happens?

    
asked by ErnestoPerez 21.07.2017 в 18:02
source

2 answers

0

Consider that when you export your jar only contains your classes , its dependencies are not exported. This is independent of the IDE, meaning that exactly the same would happen with Eclipse and IntelliJ as well. And it is the right thing to do, because your project only contains those classes and resources that you have indicated in it.

What is done in these cases is to add the libraries that your project depends on in a folder lib and indicate that the jar that are there belong to the classpath (route where find more classes) during the execution of the project .

Assuming that your jar is called miproyecto.jar and you have the following folder structure:

- usr
. - ernestoperez
  . + miproyecto.jar
  . - lib
    . + jxl.jar

Then when you locate the command line in the ernestoperez folder, you could execute the following command:

java -cp "lib/*" -jar miproyecto.jar

More information (in English):

answered by 23.07.2017 в 19:24
0

In netbeans, in your project, in the properties, you must indicate in which class the MAIN method is that will start the execution of everything.

In the project you must also have a link that libraries use (.JAR files)

Then, you give the project "Clean and Build" and look in the DIST folder in the file browser (where your project is) for the packaged .JAR file.

If you go from CMD, the command console to the DIST folder, there you can do:

java -jar paqueteMio.jar

and should run correctly.

Netbeans should put your libraries in a folder, at the same level as the created JAR.

If you take the created application to another folder or another team, remember to also take, in addition to the packageMio.jar the lib folder that should always be at the same level.

Greetings.

    
answered by 30.01.2018 в 17:05