I have a largish project that needs to be usable either with a command-line interface or through a web-app. The core server is deployed as 10 separate jars. The web-app is currently deployed as a .war, but that is a huge file that duplicates all the individual deployments and makes updating a module a big pain - you have to re-deploy this huge .war file every time you update anything, and much of the time we don't use the web-app.
So I am trying to deploy a "skinny war", without the dependencies. However, there's no .ear file to carry them, so at runtime, I unpack the skinny war and use jetty:run, with the classesDirectory and webAppSourceDirectory pointing into the unpacked content. That all seems to work. The problem is that the dependencies from the web-app module do not make it into the classpath for jetty:run. When I use jetty:run in the web-app module, the classpath includes all parent, local, and transitive dependencies. But when I use jetty:run in the "distribution" project that depends on the web-app module, the only dependencies that get into the classpath are from the parent module, not from the web-app module. Note that the web-app module is the only local dependency in the distribution module.
What am I missing?
If I'm understanding you correctly, your problem is that Maven doesn't resolve transitive dependencies for war dependencies.
Related
I want to include (import) some classes from an java package that is shipped as a war in the maven central repository but also has a jar package. Which is why its dependency xml on the mvn repository website is stated as
<dependency>
<groupId>org.camunda.bpm</groupId>
<artifactId>camunda-engine-rest</artifactId>
<version>7.14.0</version>
</dependency>
I use the dependency in my pom and my code compiles successfully. But when I run mvn clean install I get the below error:
Failure to find org.camunda.bpm:camunda-engine-rest:jar:7.14.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
Also when I add type war (<type>war</type>) to my dependency, I dont get the above error but now my code wont compile.
It is strange because when I visit https://repo.maven.apache.org/maven2 and navigate to the GAV I can find the jars
The JARs in the directory you showed have classifiers.
If you need one of them, you must add the classifier to the dependency, e.g.
<classifier>classes</classifier>
I don't know Camunda, but I would also look into the documentation. It may be better to use some other approach instead of trying the use a class of a WAR.
problem using pure spring boot "starter" dependencies that it contains camunda engine plus tomcat, so even when you remove tomcat using either or , it continues to run on tomcat as its already with in camunda engine. And when you try to create war file and paste in into shared camunda engine outside then that war will no work. This is because that war you created containing camunda engine and a tomcat inside it and when you paste into another outside camunda engine, it gets confused to which camunda to use.
See this solution : http://javaint4bytes.blogspot.com/2019/11/camunda-spring-boot-with-shared-engine.html
A possibly better approach would be to not reference the complete WAR as a dependency but the specific jars you need from it. You can add the jars you are importing from in your code (e.g. camunda-engine) to your POM instead of the complete war file. Here is an example: https://github.com/rob2universe/camunda-custom-rest-endpoint/blob/main/custom-endpoint/pom.xml
I have a maven based project and my war file would be bigger than 100M. because of firewalls and some network policies in our company, it takes hours to transfer my new war file to our server.
I want to exclude all jar dependencies and locate them into Tomcat lib. How can I handle it in maven? and how can I add my dependencies to tomcat classpath? thank you
You can utilize the maven dependency plugin in order to collect the dependencies in a folder: https://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-project-dependencies.html
If you place the libraries in the lib folder of the tomcats they are available for the tomcat common/shared classloader. If you want to put them in a subfolder to avoid mixing up with already present jars used by tomcat you can add that in catalina.properties.
If you have to deplyoy several webapps on the tomcat with possibly different versions of the same dependency you could run in very ugly problems because the loading of the libs by the common classloader is more or less "random".
I want to know why OSGi do not respect the maven dependenceis.
I want to create one app in OSGi(AEM). I want to communicate(CRUD) to the database with the help of JPA(eclipselink).
I created maven project with aem-archetype.
Added all required dependencies(of JPA) into my maven project's pom file.
No errors in Eclipse, I built the project via mvn clean install and installed it into AEM(CQ5) via mvn sling:install. All good till now. No Errors.
But when I go and see my bundle in the felix console, I see that it is not Active but in Installed state.The error reported is that it could not resolve the javax.persistence package.
I was puzzled, I searched and I read about it here -
You have to make sure that you place the same version in another
bundle and deploy first. https://forums.adobe.com/thread/2325007
I converted JPA jar to OSGi bundle and installed in my OSGi container, and the error was gone. Great!
But why OSGi is not watching out for the dependencies I wrote in pom.xml of my maven project. Why it needs JPA strictly from OSGi bundle?
Maybe this is due to any architectural benefit, but could anyone please explain me here about this behaviour of OSGi? And why/how this feature of OSGi is useful ?
The <dependency> section of your Maven POM only covers your compile time dependencies. That means when you run Maven to build your project those dependencies are used to compile the source code and build your bundle. Maven itself is not aware of AEM or OSGi or any other platform or framework (e.g. Spring).
Maven just compiles your code.
You, as a developer, are responsible that all those required compile time dependencies are also available at runtime.
What we usually do is to create an AEM content package Maven module and put all of our required third party dependencies (e.g. JPA bundles) into it. This content package is then deployed by Maven so that those dependencies are also available at runtime.
Reason is: what you are adding as dependency is getting added in build path of your project and being available for your classes.When you run mvn install,it checks presence of all dependency and creates a bundle/jar for you.By default this bundle has only your project classes not other dependencies.
You need to check in depfinder whether external dependencies are already there in OSGi container,if not you have to load them in OSGi container either by embedding external dependencies in your bundle with the help of maven-bundle-plugin present in pom.xml or by making a bundle of jar file(I wont recommend that)which you have done.
I hope this helps!
we have a maven multi-module pom project with a core-module where i want to keep common application.properties, like database-access, email-gateways etc. Is it possible to integrate those application*.properties in the executable jar of the other modules as well (jars built by spring-boot-maven-plugin)?
when taking a look into the built jar, you can see that only the module's resources are integrated, all other modules are ignored.
Thanks
I am new to Java EE. I use Maven, Eclipse and jBoss/WildFly.
I have a war project. When I build the project all its dependencies are packaged inside the war file in WEB-INF/lib.
Now I am trying to create a ejb project (I have <packaging>ejb</packaging> in the pom.xml). I want to deploy it as a separate project (not as a part of the war). When I build the ejb project Maven does not package any dependencies in the jar.
How can I package/deploy a ejb .jar with its dependencies?
UPDATE: I'd like to avoid packaging EJBs in an .ear if it is possible. (I do not want to create one more Maven project).
The best solution is package your project as ear. But if don't want use ear, maven assembly plugin can help you to package all needed jars in one file. This solution is only for "proof of concept" variant, and cannot be used in production mode, by licences limitation for example.