Maven - load all jars inside a system folder - maven

Is there a way we can load all the jar files inside a folder, as dependencies in a maven project.
So that, I do not have to mention each and every jar files in pom.xml, just mention or tell maven to pick all the jar files from folder 'x' and build the system.
Is this supported by maven?
I think this is supported by ant. Not sure whether gradle supports either.

In
https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#System_Dependencies
you see that you can reference single files, but there is no mechanism for directories. As I mentioned in the comment, using the disk is discouraged in general.
If you need the same set of dependencies in many projects, you can write a pom for that and use it (as parent or by setting a dependency to it).

Related

How to import the external libraries to target project's lib folder with Gradle

There is a transitive library that I need to use in my project, but it has transitive dependencies of several levels deep. I understand that by default all the required jar files will be automatically downloaded to the local repository, which is by default at USER_HOME/.m2 folder (my OS is Windows).
Is there a way to import all the required jar files into another specified folder? I'm planning to put all the jar files inside the 'project_name/libs' folder.
Basically, my question is quite similar to this one, but with transitive dependencies.
Putting libraries in the folder is possible and can be configured as in this tutorial. However if You use the local folder transitive dependencies will not be resolved - You need to put all the libraries in this folder if You'd like it to be the only repository for libraries. What You can do also is to exclude transitive dependencies as written here. The scenario is a bit unclear so I suppose that You probably need to use both approaches.

include source files in war maven

I want to include source files also in Maven - War file . Some plugins in maven will do that but they are including source files in classes folder. But my requirement is that when I import the same war file again into eclipse I should be able to work on that war like any other normal war.
Basically I should be able to work on the same war after importing it to eclipse when I build maven project. (I'm using maven3. )
I remember that's not trivial because the war-plugin doesn't support the handy includes-configuration-element you know from the jar-plugin by default.
Therefore I suggest you to use the maven-assembly-plugin to configure the inclusion of your sourcefiles. You only need to define an assembly descriptor, where you list includes and excludes of your war-package. Maybe you can reuse one of the predefinied assembly descriptors to save some time.

how to exclude some setting files from the jar file when using Maven?

As the testing environment and the development environment are different, and testers may changed the setting files in src/lib, how can i set up Maven to make sure these settings are excluded from the file jar generated by Maven but are put in a certain folder?
thanks!
The src/lib directory is not included in the artifact, unless you have explicitly told Maven to do so. If you are using these resources as test resources, you should put them underneath src/test/resources to avoid any possible mix-ups. Furthermore, you can have Maven profiles for you different kinds of tests, if you need so.
The src/lib folder is usually not included into the created jar file.

Maven compile all source files, but include into jar only few of them

I have source folder with more than 500 source files.
I need to produce 4 Jars from this sources.
But there is one problem when i try to compile sources needed for my first jar they dont want to compile because, all sources are needed to compile my specific sources.
and here is the question: if i compiled once all my 500 source files with maven how i can split them into several JAR files? i dont need that all my for 4 jar were containing all 500 sources, each JAR must contain only their specific .class files...
With ant it was very easy, u just compile all sources once, and then when creating JAR u just include specified .class files into jar, and no problem... Can some thing similar be done i n MAVEN?
You should split your source code in multiple inter-dependant java projects.
Then, make each project compile to a jar.
I really recommend going Tristans solution but you should also achieve what you want by configurating the maven-jar-plugin to exclude/include the content that you (not) want. This is described here (see How to include/exclude content from jar artifact?).
As you can only build one artifact with one pom.xml (in general) you have to prepare several pom's (or you try the <classifier> configuration also described on the maven-jar-plugin Usage page (I never used it but it seams to help you to do what you want).
You SHOULD split this jar project into Multi-Module jar project. This will solve your problem and project structure will be much better.

IntelliJ: Including jars in a jar artifact

Developing on the Mac with IntelliJ 9.0.2 Community Edition.
I have a program which depends on two library jars. I have figured out how to get IntelliJ to make me a jar of my source (with the Artifact tab), and even to include the two jars in it.
However, if I get a listing of the jar file it produces, it looks like this:
com/acme/MyClass1.class
com/acme/MyClass2.class
...
mylib1.jar
myLib2.jar
And, no surprises, if I double-click the jar file, it gets a NoClassDefFoundError the first time it tries to access a class in one or other library jar.
It seems I need to tell IntelliJ to "inline" the library jars -- but this menu option is always greyed out!
Does anyone have any idea how to get jars inlined in a jar artifact?
IDEA doesn't support it yet, you can use Ant integration to package your jar (either by unpacking all the jars into the temp folder and then packaging the project output plus this temp folder into the single jar or by using some Ant task like jarjar).
If you want this feature to appear in the future IDEA versions, please vote for the request.
Having the dependency JARs included in your JAR should allow yoru code to run successfully. You probably don't have the JARs on your classpath.
I will use Maven Assembly plugin. Its simple and will give you a neat little jar file..

Resources