0

This is a follow up to this question: creating an uber jar with spring dependencies

I have created a web service using Eclipse, which is running on Windows. I need to run it as a jar on a Solaris station and there I get the ClassNotFoundException:

Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358

I want to create a big jar with all dependencies but I don't understand the answer to that question above.. where do I add what he wrote? And then do I just need to export a jar as usual using Eclipse's export option?

Community
  • 1
  • 1
CodeMonkey
  • 11,196
  • 30
  • 112
  • 203
  • Possible dupe (and likely clearer explanation): http://stackoverflow.com/q/25994145/1079354 – Makoto Sep 17 '15 at 15:18
  • First question, a webservice launched as a jar ? i'm quite sur that you need a webserver to run it no ? Second question, which class is not found ? – vincent Sep 17 '15 at 15:19
  • @vincent I have added the exception. And after developing the web server on Windows I was given a Solaris station on which the web service should run. Should I not move it from windows as a jar? – CodeMonkey Sep 17 '15 at 15:31
  • you use Spring boot, that's an important part of the question. In this case you can. I don't know it very well, did you try a simple tutorial like this one first https://spring.io/guides/gs/spring-boot/ ? add "spring boot" as a tag you will have more answers i hope – vincent Sep 17 '15 at 15:37
  • @Makoto I have looked at that question and the answer is unclear. Everyone just keep writing some xml maven definitions to add but no one is saying where to add them? which file? and what do I do after I add them? – CodeMonkey Sep 17 '15 at 15:57
  • You can use maven as a tool, when you use it, your project has to follow some conventions. In this convention, your project needs to have a descriptor called a pom.xml. https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html – vincent Sep 17 '15 at 15:59
  • I did insert the lines to the pom.xml file under the plugins tag which is under the build tag. Do I need to do something so that the added lines will take affect? In order to create that uber jar after adding these lines, do I simply create the jar file as always using Eclipse's export? – CodeMonkey Sep 17 '15 at 16:02
  • nope, you have to run 'mvn package' – vincent Sep 17 '15 at 16:04
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/89934/discussion-between-yonatan-nir-and-vincent). – CodeMonkey Sep 17 '15 at 16:11
  • Spring Boot already creates a jar with all the dependencies itself. When you are adding things like the shade plugin that will only break things, don't do that. Just use the Spring Boot maven plugin and well be done. – M. Deinum Sep 18 '15 at 11:34

1 Answers1

1

What no one ever said in the answers to other questions is that you need to use maven to create the jar and not using Eclipse's export to jar option. What you need to do is:

1) download maven from https://maven.apache.org/download.cgi

2) The maven dir contains a 'bin' folder. Add this folder to your "path" enviornment variable (on Windows 8 right click "This PC" -> properties -> Advanced System Settings -> Environment Variables -> in System Variables find "Path" -> double click it and add it by adding the bin folder path to that variable the same way other paths are located there.

3) open CMD

4) navigate to your project's folder

5) type mvn package

The jar file is created inside the "target" folder.

Good luck

CodeMonkey
  • 11,196
  • 30
  • 112
  • 203