I have 3 projects
Webapp1 and Webapp2 and a 3rd project i called SharedProject
Both webapps1,2 are using the sharedproject classes.
I would like to include the sharedproject as a jar in both of them.
In eclipse i could set for each project that it depends on the 3rd project and on every war file i export it will attach the jar automagically.
Is there a similar easy way with gradle? I couldnt find any tutorials for this specific concept.
Thanks!
Adding the shared project as a dependency in the other projects should do it, e.g.:
dependencies {
compile project(':SharedProject')
}
Related
I have just started working with Maven in Eclipse.
I tried running a sample program in it, and I encountered some problems. The errors were in my pom.xml file. What is the significance of the pom.xml file in Maven?
In short the pom.xml will have all information to build your project.
For example you want to build a project and you have only the pom.xml sent to you via mail. If there are enough entries in the pom.xml then that is all you need! You can import it to Eclipse, Maven will download your source code from CVS, download various dependency jars (like Spring, Apache Commons), run your test cases, build the jar/war, deploy to your jboss/app server, generate a report of your code quality (using Sonar, maybe). Each task you want to do will be mentioned as a goal.
The links already provided are good enough for reference.
POM is an XML file that contains the project configuration details used by Maven. It provides all the configurations required for a project.
POM means Project Object Model, and, as the name suggests, it defines the model of the project as well.
In the normal project development you will add JAR files and libraries as required. In Maven-based development, those JAR files, libraries are added to the project using this pom.xml. In the pom context we call those JAR files, libraries as dependencies.
Maven is a build tool and pom.xml is the main file for the project.
The POM
The pom.xml file is the core of a project's configuration in Maven. It is a single configuration file that contains the majority of the information required to build a project in just the way you want. The POM is huge and can be daunting in its complexity, but it is not necessary to understand all of the intricacies just yet to use it effectively.
For more reference, check Maven in 5 Minutes.
POM stands for project object model. It's the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used to build the project. It downloads required libraries easily using POM XML tags.
When there is no Maven, it needs to add all the library JAR files one by one to the project. But when there is Pom.xml there is no need to add library JAR files one by one.
Simply add the dependency to the Pom.xml, and it will automatically add the library JAR files to the project.
pom.xml is a file which describes the project, configures plugins, and declares dependencies. The POM names the project, provides a set of unique identifiers (called coordinates) for a project, and defines the relationships between this project and others through dependencies, parents, and prerequisites.
A POM file can include a modules section, which tells Maven which directories have POM files which need to be built.
In the build section you can define plugins for which you need to build the artifacts in your project.
Pom.xml is part of your maven project, using pom.xml, maven life cycle you can achieve it.
The pom.xml is a project object model which tells everything 3rd party tool dependencies and library's and required plugins it will give everything to your project like project means any java based web content like itself. once you create the maven project you will get the pom.xml blog which is everything to handle your project
If you want to test your project, you need to add testing dependencies which is the maven community it will provide you once added it will have everything tested.
I am trying to use loaded jar files of my class path into my module. I
know requires will accept only modules names.
my jar files are present inside the Spring Jar Files folder.
I tried to use #Configuration annotation inside my appConfig.java file and IDE could not recognize it.
Your help is much appreciated as I am new to the programming world.
Normally, I use Maven or Gradle to handle all the jars.
It seems you have just started with Spring.
I suggest you try Spring Boot with Maven or Gradle to manage the library and the code lifecycle (compile, build, test).
This is one tutorial for example: https://spring.io/guides/gs/spring-boot/
You can add a jar in Eclipse by right-clicking on the Project → Build Path → Configure Build Path. Under Libraries tab, click Add Jars or Add External JARs and give the Jar.
Example link
The above solution is obviously a "Quick" one. However, if you are working on a project where you need to commit files to the source control repository, I would recommend adding Jar files to a dedicated library folder within your source control repository and referencing few or all of them as mentioned above.
I'd suggest go for the second one if you are planning to build this as a proper project and put it in a source control repo.
I have a library project which is built in maven. It has its dependencies. I need to export this project as a jar (Not a runnable jar). Should I include the dependencies along with my jar or should I not? Because when I exported the dependencies with my jar, there were conflicts when the same jars of different versions were used for projects that added this project as a dependency. But if I don't export with the dependencies, at run time this library project throws NoClassDefFound errors for its dependencies. So what is the right way to do this? If I don't export the dependencies with my jar, is there a way that the project using this library project could download those jars for the library project? If that is how I would do it, then wouldn't it mean that the project using this project must be using maven too? It won't be a good practice as whoever uses this library should be able to use whatever the build tools they want. I am pretty new to maven. Please advice.
It is largely to taste, some open source projects do both, providing with for and without so that it is easier to use in larger projects.
If you are using Maven for your other projects you can, when you declare a dependency on this library tell maven to exclude some of its component jars.
In Eclipse, I have two projects:
archangel.core - a Maven project
ArchangelWEB - a Dynamic Web Project (built for Tomcat).
The first, archangel.core has all of the base code and uses Maven to resolve dependencies. The second is the Web addition on top of the core project. This only has code specific to presentation/view. I want to keep them separate because I may have other projects in the future that will rely on the core, and I don't want the core project to have Web Library dependencies.
Right now, in ArchangelWEB's build path, I have the archangel.core project, and I also have archangel.core in its Deployment Assembly. This allows me to refer to code from archangel.core in ArchangelWEB without any build or runtime problems.
One of archangel.core's dependencies is apache-commons-lang. Within archangel.core, I can reference classes like ExceptionUtils. However, I cannot automatically reference this jar dependency from ArchangelWEB. If I try to import class from apache-commons-lang in ArchangelWEB, it doesn't know what I am talking about.
What is the best way to import/reference dependency jars from a maven project into this other project (my Dynamic Web Project), which uses the maven project as a dependency?
Dynamic Web Projects resolves dependency only by manually placing the Jars in the WEB-INF/libs folder. There is no other way.
So you need to place the dependent jars of your Dynamic Web Project into the libs folder manually.
Don't forget to do Right-click the Jars in Lib -> Add to Build path after adding them
This is why we use maven these days instead of the old Dynamic Web Projects.
My application use ViewPageIndicator, HoloEverywhere, ActionBarSherlock, and all it uses android-support-v4.jar library. But when I include this library into /libs folder of each module, it causes build error:
com.android.sdklib.build.DuplicateFileException:
Duplicate files at the same path inside the APK
at com.android.sdklib.build.ApkBuilder$JavaAndNativeResourceFilter.checkEntry(ApkBuilder.java:125)
...
If I remove these libraries from any module, build failed in this module, because can not find library classes.
How to fix it and build the project?
Do you need the modules to build on their own, or do you just need your application to build? Assuming it's the latter, what happens if you include the jar in only your project? Eclipse may not like this since there will be errors in the workspace, but at least with command-line Ant, you can just reference a library project without building it ahead of time and your app should compile, since it will pull in all the classes/resources and build everything at once.
I.e., suppose:
projectA references libraryProjectB
projectA depends on libFoo
libraryProjectB depends on libFoo
Then try:
put libFoo in projectA
build projectA only
Not positive this will solve your problem, but I encountered a similar situation with shared C/C++ libraries and leaving them only in the library project solved my own issue, so hopefully this is helpful.