0

Is there any web service that runs as a jar?

I've already tried using spark but besides from running a jar I need it to be able to render jsp files.

My current scenario is that I have a tomcat(.war) project that depends on another project(.jar) and I want to add some web functionalities to this second project. However I cannot change it to a .war as one .war project cannot depend on another .war project.

Any help or guidance would be appreciated.

  • Why not embed the JAR file you want to enhance into a WAR? (You can also consider other app servers, but I dont see. Separating the web part from the JAR lib is good practice anyway. – eckes Nov 24 '16 at 19:39

3 Answers3

1

I'm facing a similar issue, and my workaround is less than elegant but I haven't found a better one yet.

To restate the issue:

  • ProjectA.war depends on X.class (or more) from Project B.jar
  • ProjectB.jar needs to be repackaged as Project B.war

The solution I'm going with:

  • Convert ProjectB.jar to ProjectB.war as needed
  • Manually extract the ProjectB.jar file from ProjectB.war and cite that extracted .jar as a dependency in ProjectA

(I followed How to extract .war files in java? ZIP vs JAR)

Depending on your build system you can also set ProjectB to build both a .war and a .jar for dependency at the same time; I'm using Maven and that's the path I'm eventually going* so that I'm not manually digging out the .jar each time I update ProjectB, and then I'm just going to list that .jar as a dependency for ProjectA.

* = http://maven.apache.org/plugins/maven-war-plugin/faq.html at the bottom of the FAQ, "How do I create a JAR containing the classes in my webapp?"

Community
  • 1
  • 1
Sam Abazly
  • 76
  • 4
  • Could you point me towards the maven solution? My projects are also maven projects and that seems like a cool solution that would actually help in more places. – Bruno Henrique Nov 24 '16 at 21:45
  • Yeah, I'm looking at the bottom of this page: – Sam Abazly Nov 25 '16 at 14:58
  • Well, I fail to not double post: https://maven.apache.org/plugins/maven-war-plugin/faq.html it's the bottom of the FAQ, "How do I create a JAR containing the classes in my webapp?" – Sam Abazly Nov 25 '16 at 14:58
0

Put the common code into the jar. (Refactor that code to a new module whithout the front end parts).

Add that jar as a dependency in the wars.

Or if you can afford it, just start migrating to microservices where the "tomcat" is inside the jar and not the other way around.

For instance using Spring Boot

Fernando
  • 396
  • 1
  • 5
0

You should not add web functionality on your JAR file. The better solution is to have a JAR library common to your two web services. Also, I recommend spring boot for your second web service because it's easy to use and configure, you could have jar web service on a jiffy (Embedded inside it is tomcat).

Here's a sample: +----------+ +----------+ | WAR | | JAR-WS | | +-------------------+ | | | COMMONS | | | +-------------------+ | +----------+ +----------+

dapregala
  • 41
  • 2