I want to build a runnable jar for a JavaFX application which uses depency injection (Spring framework libraries) to manage multiple FXMl files and multiple FXMLDocumentControllers. However, when exeuting the jar a "ClassNotFoundException: org.springframework.context.annotation.AnnotationConfigApplicationContext" is reported. Yet, I have added Spring library (3.2.7) to the project in Netbeans and it functions well within the IDE. How can I assure, that the above class is available in the jar as well?
Asked
Active
Viewed 147 times
0
-
Since you're using maven, could you share the dependency definition to spring-context that you have added to your pom.xml? The tag is added to the question, but I have to ask: are you using maven for packaging your jar? – Cristina_eGold Aug 02 '16 at 14:48
-
@deepdownunder2222 You are absolutely right. I was wondering if perhaps I have to use Maven to solve this problem? So I added the tag. Is it obligatory to use Maven in this context, and what would I have to write where in the pom.xml? (I'm sorry for being so unexperienced with maven and dependency management) – MyrosinaseM Aug 02 '16 at 14:54
-
You could create a fat jar from it, including the necessary classes. – ManoDestra Aug 02 '16 at 14:56
-
The recognized way to create a jar file for an FX application is to use the FX packaging tools: see the [deployment documentation](http://docs.oracle.com/javase/8/docs/technotes/guides/deploy/). Both the `javapackager -createjar` command and the ant tasks have options for including external jar files. This is also automated via Netbeans (which I don't use, so I don't know the details), but the linked documentation says this should happen via the project properties. – James_D Aug 02 '16 at 15:02
1 Answers
0
When compiling and packaging your code, the resulting jar usually only contains YOUR code. You need to add the dependent jar files to the classpath. What that means is, whenever you invoke java -jar yourapp.jar some.package.MainClass
to run your application, you need to list all required jar files in the -cp
option of the java command.
Another (bad) solution could be to use maven's assembly plugin (or some other means) to create a fat-jar, which essentially is a merge of yourapp.jar
and all dependent jars.
-
Note that there are [specific tools](http://docs.oracle.com/javase/8/docs/technotes/guides/deploy/) for creating jar files for JavaFX applications. – James_D Aug 02 '16 at 15:02