Maven how to exclude jar files in war but need it for the build - maven-3

I am new to maven.
I am using maven 3.6.2
I am using jdk 1.7.
Any help or hint would be greatly appreciated it!!
I have a dependency in pom.xml:
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</catalina>
<version>7.0.12</version>
</dependency>
I need the above dependency to do a build:
dos-prompt>mvn clean install
But when use it in a tomcat 7 I need to exclude the above jar file in the war file that is the result of the build.

Related

How to fetch the latest released version of a dependency included in my pom.xml

Instead of manually changing the version each time, i want the maven to load the released jar version automatically.
I'm using Eclipse with embedded Maven version 3.5.4
Could you anyone suggest on how to resolve this ?
I have tried LATEST and RELEASE keywords in
LATEST
But it does not work.
If i use version range like
[1.70.4,) it loads the snapshot version which i do NOT want
i have added the below mentioned dependency in my pom.xml
<dependency>
<groupId>com.xxx.portal</groupId>
<artifactId>portal-xxx-integrationtests</artifactId>
<version>1.70.4</version>
<classifier>tests</classifier>
<type>test-jar</type>
<scope>test</scope>
</dependency>

What to modify when upgrading Struts from 2.0 to 2.5?

I have a big project running on Eclipse that uses Struts, I want to upgrade Struts from 2.0.11.1 to 2.5.3.
However, I checked the Migration Guide but there was no info detailing what should really be removed, updated, added, etc..
I downloaded struts 2.5.3 and there are a lot of libraries, plugins, source files, etc..
My question is that can I upgrade Struts from 2.0.11.1 to 2.5.3 directly?
If yes, then what should be changed and how will this be done?
If no, kindly propose a solution.
When you upgrade the version of Struts2, you have to update the libraries requires by your application to the target version. Each Struts2 release is supplied with the corresponding set of libraries in the lib folder that are compatible with the version of Struts. If you use maven to resolve and fetch the dependencies you should consider the artifact struts2-core.
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.5.3</version>
</dependency>
It will fetch all required dependencies for this artifact, other dependencies, such as plugins you need to add separately. Use the same version targeted to plugins. For example to add a convention plugin use
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>2.5.3</version>
</dependency>
The targeted version number is 2.5.3, but it's possibly incompatible with the other features i.e. Hibernate and Spring which versions need to upgrade separately by adding corresponding artifacts to the dependencies.
And finally and most time consuming are changes to the source code of the project, update the configuration files according to newer DTDs, API changes, fix deprecations. For this purpose consider reading the release notes.
You can't upgrade Struts2 just changing the major version number.
Also see the example of developing a maven project: Create Struts 2 Web Application Using Maven To Manage Artifacts and To Build The Application.

Missing maven dependencies in project converted from java to maven

I converted a Java project to maven project. But there are still maven dependencies not in the build path. There maven dependencies do not show up in the lib path.
Once you have converted your project to maven (i.e) you have to do the following in eclipse:
Right Click on your and select Maven --> Update Project
This will rebuild your eclipse and all dependencies that is defined in that project pom.xml will be added to your build path under Maven Dependencies.
In general all your dependencies will be downloaded to .m2 folder in your system. This will generally be inside your home directory unless you change it in the settings.xml.

How to add project dependency (classes from another module/folder) in Grails?

Is there a way for me to add dependencies from other folders/projects(non-grails, but definitely java projects) into my grails project? I've tried searching but didn't really get much of an answer. :(
You can use every possible library which is in a maven repository. So transform your java project to a maven or gradle project. Install your builded jar to maven repo and then you can add dependency in grails-app/conf/BuildConfig.groovy.
dependencies {
compile "your.group:your.artifact:1.0"
}
You have to get the code into your project somehow.
These are the options:
JAR
Package your module as a jar file and copy this to your project's lib/ directory.
source code
Copy the source code for your module into src/java/
Maven Artifact
Package your module as a maven artifact, and specify it in the dependencies closure of grails-app/conf/BuildConfig.groovy.
Read more in the grails documentation at http://grails.org/doc/latest/guide/conf.html#configurationsAndDependencies

How to build project dependencies from source jar-s with maven

I have a project, which is building with maven 3. While building project maven downloads a lot of dependencies (jars). I want to build all this dependencies from source-jars, which I get from maven repository with maven dependency plugin.
But this source jars doesn't contain any pom or other things for building. How I can build them with maven??
You can't. You need to get the source from the project's source repository. The source-jars are just for helping developers debug dependencies.

Resources