I have two maven projects, one (I will call it core) is an ejb-jar (ejb) and the other a war (client).
My client project consumes some ejbs inside my core...so far so good.
But I'm getting a ClassNotFoundException inside my core application because it can't find one class from apache-beanutils...I have set this dependency with compile scope in it's pom.xml but it does not get shipped inside the output jar.
When I check my client.war package I see every compile-scoped dependency inside the WEB-INF/lib folder...but in my core.jar I don't see any of it's dependencies...I'm totally confused about this.
Can someone help me? I tried to google it before asking but I didn't find anything useful so far..thanks.
You can use the maven assembly plugin to bundle all the jars in one super jar.
See this: question
Related
When we use scope tag while providing dependencies in POM file of Maven, we can give several valid values (compile, run, provided etc..). I understand that tag is applicable for only transitive dependencies (i.: list of JARs required by direct dependencies that we give in POM).
When we give the scope as provided, will the dependency not be downloaded from Maven central repository ? Can someone please confirm.
Thanks!
Dependencies with scope provided are meant to be provided by the container in which the application runs (e.g. provided by jboss).
This means that they are downloaded by Maven, put on the compile and test classpath, but not included into the final WAR or EAR you are building.
I have a spring boot application with maven.
I need to use an external jar say "tp.jar". I have used the method of system scope to do the same but seems it has been deprecated. Is there any better alternative which doesn't involve running maven commands to do the same. I found some solutions here Can I add jars to maven 2 build classpath without installing them?
But the posts are pretty old was wondering if any new solution and convenient solution has been found.
If you are in a company doing Java, you probably have a Nexus or Artifactory server running. This is the place to put the jar. Then you can use all Maven mechanisms to use it.
I am building a rest API for a previous project. If I add it as dependency to my new rest API project, will all the functionality will be added to my rest API jar file or only the methods which I use? My old project jar is 181M, so the whole will be added to Rest API jar?
Thanks,
Without special configuration, Maven will not include any dependencies in your jar at all. Just the compiled classes from your source code (and generated classes) are included. If you want to include dependencies, you have to tell maven using the maven-assembly-plugin, as described in How can I create an executable JAR with dependencies using Maven?. When you use a different packaging, the dependencies can be included automatically, depending on the packaging type. E. g. when using war, all compile dependencies are added to WEB-INF/lib.
When you include dependencies, always the complete dependency-jar is added to your jar. There will be no checking, if everything is needed. So, your resulting jar will contain all 181M of dependencies as well as the source code of the new project.
This is a strange problem. I have an existing JEE project that is and has been in production on WebSphere 7. It is a multi-module EAR file. It has 2 WARs and 1 shared Java project. Most of it is Spring 4 based, but we have some web services we host using axis2 (1.5.4). This project does not use Maven. It does use a WebSphere deployment.xml (in the EAR) with the warClassloaderPolicy="SINGLE" and the classloader mode="PARENT_LAST". This controls the classloader policies for this EAR. All the jar files that the Java project and the WARs rely on are stored at the EAR level and referenced at the module level via the manifest files. That all works fine and has for several years.
Now I was trying to convert this project to a Maven project after all these years. Initially, I left the deployment.xml file settings as they always have been. But with these settings I was getting:
java.lang.VerifyError at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl "org.springframework.oxm.jaxb.Jaxb2Marshaller".
After much googling on this site and all around and trying 50,000 things, I tried one thing, which worked for most of the app. I switched the classloader mode to "PARENT_FIRST" and all of a sudden the WAR that exclusively uses Spring 4 worked. It started up without error and I was able to run it.
But, the other WAR which hosts the axis2 web services started getting the error:
org.apache.axis2.deployment.WarBasedAxisConfigurator <init> org.apache.commons.fileupload.FileUploadException....Caused by: java.lang.NoClassDefFoundError: org.apache.commons.fileupload.FileUploadException....Caused by: java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileUploadException
This class (org.apache.commons.fileupload.FileUploadException) is in both the compile and runtime classpath. In eclipse I can see it in the "Maven Dependencies" library that the m2e eclipse plugin creates from the POM files. I can also see this jar in the WebSphere runtime module classpath inspector (it shows up in there 3 times! Once under each WAR and once just in a list from the Maven repository location.)
One thing of note is that I've configured the project with a parent POM, where most of the dependencies are declared at the parent and then are inherited for each of the modules. In the EAR project, the POM is using the maven-ear-plugin with skinnyWars=true. However, it appears the skinnyWars directive is not respected when the m2e eclipse plugin deploys the EAR into the local WebSphere server (that is evident because I see these jars showing up in the classpath 3 times). But when I create an EAR using the Maven build, the EAR comes out correctly with each jar only showing up in the EAR one time.
This is my last hope to post something here and see if someone has an idea for something to try, otherwise I can't think of anything else to try.
Thanks...
Is there a particular reason you need to run with a single class loader for all the WAR modules, other than convenience? If not, you could rework the application in order to allow you to run PARENT_FIRST in the Spring WAR and PARENT_LAST in the Axis2 WAR.
If that's not an option for some reason, the path of least resistance might be to go back to PARENT_LAST and remove some libraries from the app or module. The VerifyError generally occurs if you're running with PARENT_LAST and have a library in the app that is also present in the server - in this case, the exception looks like it's coming out of JAXB, so you might want to see if simply removing JAXB (and perhaps JAXP, if present, since it's heavily used by JAXB) from the application resolves the issue with your default setup.
You could also stick with PARENT_FIRST and move the Axis2 jars to an shared library with an isolated class loader, associated with the app. An isolated shared library would make just the stuff in the shared library PARENT_LAST, so you can avoid the VerifyError and still get PARENT_LAST for Axis2. The issue in the PARENT_FIRST case appears to be because you're picking up WebSphere's copy of Axis2 but somehow have a dependency inserted from your app's copy - the failing class load is occurring in a server-level loader, so it doesn't see the copy in your app.
I have an ear application which has 3 modules:
web.war
services.jar(ejb)
domain.jar(ejb)
I worked with maven tutorial:tutorial
At the end author says about problems with manifest.mf in web module and suggesting some solutions. But this not worked for me. I think configuration is broken not only in that case. In my ear MANIFEST (classpath) i have also prefix "lib/" before services module(services are separated jar as ejb module in my app).
I saw i can use my specific prepared Manifest.mf, but i don't know how to configure it manually. Could I duplicate jars in my app modules? For example add domain.jar in services and web? Is it correct?
I have specific structure:
1.sample-ear with web and services module
2.sample-web with sample servlet(without dependencies from other project in code).
3.sample-services with dao classes(using entities)
4.sample-domain with entity beans
I tried modify manifests in every package, but I didn't find a solution. When i want to run my application on WildFly10 i get NoDefClassError (Class from domain.jar used in service.jar). Could anyone help to configure it?
On the other hand maybe you have better maven configuration in project and manually configuring the manifest.mf is not needed.