As we do in Ant build, we can specify the Jars that we need to copy in build.xml in case of Ant(We just need to specify the folder name from which we need to pick the jar files). Is there any facility of same kind is available in Maven as well.
If yes, Then do we need to add the dependency tags equal to the number of jars in folder or one dependency tag is sufficient. I hope you get my point.
I think your missing the point of dependency management. All the JAR's required by your project should be defined as dependencies in your POM. If you have any custom JAR files (not available in a public repo) then you will want to install those in a local repository, and access them that way.
Related
I am trying my luck in eclipse to achieve something that I am able to successfully achieve using Visual Studio(.net project). I have a core-framework maven project with additional files and folders apart from the normal folders that maven provides. I exported it as jar file and added it as an external library to another maven project. Is there a way that when I add it as a library to the second project, the second project gets all the folders, files from the first maven project overwriting the pom file in the second maven project too? Inshort I want to make sure whoever takes the framework jar as reference follows the same folder structure as framework with required files such as config file, pom.xml file to avoid errors on missing path/files. I read about dependency management but even for that I have to define all the dependencies in child pom file which I want to avoid. Any help would be appreciated, I didn't find much info around the query.
Copying JAR files to lib folders is old-school. Such you also set aside Maven's sophisticated dependency (and transitive dependency) resolution. The clean Maven way is to put your core-framework JAR to a Maven repo (remote or local at the users machine) and let the users of it declare it as dependency in their projects.
What do you exactly mean by "additional files and folders apart from the normal folders that maven provides"? What is there more than code and resources?
To make your users' life easier concerning dependencies you could a) use a BOM (Bill Of Material) dependency or b) use inheritance (i.e. <parent> ← child relationship).
Adding a dependency will not change your project in any way. You cannot add folders from a dependency to the project.
You can write a Maven archetype that is a kind of project template. Then people can use it to create new projects where the files are at the right places.
I have downloaded ojdbc14 jar from the internet and copied it to the lib folder of my maven project. Is it necessary to add dependency in pom.xml as well. Currently working without adding.
You can use tricks to manually upload a jar into the lib folder, but it does not make sense. And it would work cause the build process will just look for that jar into the lib and if found everything will compile nicely. BUT....
Maven is a useful tool that helps you handle dependencies, internal, external, third parties, any kind, it's one of his benefits, don't need anymore to look around for jars, and put them manually into the lib dir, but why? You would override one of the basic behaviour of Maven.
Maven set lots of rules to give you the ability to manage them the way you want, you have options about how to handle every single dependency of your project, you can point to a local jar within a dependency, you can set the scope of the dependency, the type you can exclude some of the inherited transitives, and so on...
But this is the standard approach for standard situation
You should simply define the dependency, maven will downloaded from the configured repo or the default one, maven central, and retrieved from your local repo if there are no updates on that artifacts all the other time you will build that artifact.
If you have issues with licenses for ojdbc14 then the solution is configure the oracle repo where you can easily download it.
There is a 3rd party jar which is dependent by many programs on the target machine. That jar file is named as abc.jar.
I can add the jar file to the local repository as abc-1.0.jar and package my project. But that means I must manually replace abc-1.0.jar when abc.jar updates. Here are my questions:
1.Is it possible to just use abc.jar when development with Intellij IDEA? I tried add the abc.jar to the External Libraries with dependency adding. But the editor can not recognize classes within abc.jar
2.If the answer is yes, What should I do to let the war file use the system level's abc.jar not the bundled within the ear?
Many thanks
Find this?
correct-way-to-add-external-jars-lib-jar-to-an-intellij-idea-project
or compile files in Gradle
compile files("src/main/resources/libs/sqljdbc4.jar")
put jar file to path
You can add the abc.jar file to the particular module's dependency manually as described in mentioned SO answer and you also will have to manually add it to the artifact which is automatically generated by IDE based on Maven configuration.
Note that the artifact configuration will be overridden on the next re-import from Maven unless you create a copy of this artifact configuration and give it another name.
Generally such approach is not recommended for Maven project. Instead you should relay on Maven configuration.
In my Maven project , I have certain dependencies which should be present inside the WEB-INF/lib . I cannot put all the jars inside WEB-INF/lib , only the selected ones . How to go about doing this?
I cannot use the maven-resources plugin since then I would have to mention the entire jar's name inside <include> tag and I need to keep it dynamic.
I tried using <packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes> but this not give me an option to insert only selected jars inside the lib folder.
I also tried using <scope>provided</scope> for some of the jars but due to this the name of the jar doesn't get added to the classpath field inside manifest.mf file.
Please suggest some solution. Thanks in advance!
You can use Assembly plugin and customized assembly descriptor. In descriptor you can set which jars you want to copy with their artifact id, group id, version and scope. it also supports regex. https://maven.apache.org/plugins/maven-assembly-plugin/advanced-descriptor-topics.html
This may not be the best way to package the content for the WEB-INF/lib/ nested directory in a WAR file, but the implementation presented in the question for How to put all required jars in a lib folder inside the final jar with maven (using the maven-dependency-plugin plugin) solved my JAR needs for bundling all dependent jars into the lib/ directory of my final jar. Oddly it's a commonly asked question, with many different solutions. This implementation actually bundled the jars inside the nested lib/ directory, while others, for example, extracted the contents of my dependent jars and laid their classes beside my classes. So this might get you a little closer but probably not the official way of handling a WAR files' library deps.
I have some jar files that I need to include in my build - I'd rather not specify them as system dependencies - that creates a nightmare for setup. I have been uploading them to artifactory and then they can be pulled down directly, but I won't always have access to artifactory while building.
What I was thinking of doing is creating a project that has these jar files in them. It could be one per or all of them (open to suggestion). I was wondering if there is a graceful way to handle this?
What I have done (which is clearly a hack) have a project that takes the jar and during the compile phase it unpacks the jar into the target/classes directory. It then packs those class files back during the package phase. it essentially creates the same jar file again...massively hackey. Could I add the jar into the resource area or is there a different project type I could use? I am open to any ideas.
You may try to use install:install-file. I would go about it in the following way.
Create project that contains all your jars in some location
Configure install:install-file in pom of this project to install jars in repository in some early phase.
Make sure that this pom is executed before anything else that depend on it. List it as first module.