Migrate maven project in offline environment - java

I have created a web application in spring mvc and now i have to migrate the project to an offline machine but when i imported the project in my eclipse(offline) then it got stuck on "Importing Maven Projects" and also it is showing an error in my pom.xml file at tag :-
<plugins>
<plugin> // shows error over here
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
I also read something about mvn dependency:go-offline so I tried it but couldn't exactly understand that where it saves the dependencies?
So, is there a way through which i could import the project in the offline environment?

As pointed out by #Thomas, the only way to build a project which needs external dependencies with Maven is to copy the repository in the target environment. Build your project on an online environment, then copy your .m2 folder in the offline one. The build will then find all required libraries locally.
With mvn dependency:go-offline you tell maven to download all the needed plugin dependencies in your local repository.

Related

How to change JAR build path in Jenkins?

I am building a Java project via Jenkins. The JAR is being created (after I execute maven clean install in Jenkins) in C:\Windows\System32\config\systemprofile.m2\repository\com\other folders.
Is there any way to change this path? I want to sent the JAR to a VM via SSH. However, I am not able to access this folder since this is system directory.
Thank you.
For some reason, your Jenkins uses this directory as local Maven repository. I would define a different local repository in Jenkins or in the settings.xml. It is also important that you make sure that no two running builds use the same local repository at the same time because local repositories cannot be used concurrently.
If you are using maven to build, add the below to your pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<outputDirectory>your custom location</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
By default, maven should create your build artifacts (including the JAR file) in target directory next to your pom.xml.
You can change this behavior in pom.xml by specifying the build directory:
<build>
<directory>/some/other/dir</directory>
</build>
The directory you are referring to is your local maven repository, which contains all JAR files maven is working with. You can read more about local maven repository here.

Eclipse Maven Dependency - weaveDependency issue

I am new to maven but not to java or Eclipse. I imported an existing maven project into Eclipse and I am having trouble with one of the dependencies. it is listed in POM.xml with groupid of net.bootstrap.api , version 2.0.1
but maven can't find it on the central repository. it is a weaveDependency. if I change groupid to org.webjars, bootstrap can be found with a different version, downloaded, and listed in Maven Dependencies, but it won't resolve as an import. Can someone tell me how I might get this issue resolved? The POM XML snippets:
`<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.11</version>
<configuration>
<verbose>true</verbose>
<showWeaveInfo>true</showWeaveInfo>
<complianceLevel>1.8</complianceLevel>
<Xlint>ignore</Xlint>
<source>1.8</source>
<target>1.8</target>
<weaveDependencies>
<weaveDependency>
<groupId>net.bootstrap.api</groupId>
<artifactId>bootstrap</artifactId>
</weaveDependency>`
<properties>
<dagger.version>2.11</dagger.version>
<build.version>1.0.0</build.version>
<bootstrap.version>2.0.1</bootstrap.version>
The error I receive when I build with clean install, is "Failure to find net.bootstrap.api:bootstrap:jar:2.0.1 in https://repo.maven.apache.org/maven2
I tried getting bootstrap from org.webjars (which does not have version 2.0.1) and changing the imports, but the imports won't resolve. I think I need to understand how weaveDependencies work since all the other Maven Dependencies are downloaded and the imports are resolved--this bootstrap is now the only issue.
This is an open-source project from a vendor and I just discovered that others are having the same issue and is due to missing (propriertary) files. so this is not something anyone else can answer, I need to acquire the source files from the vendor.

IntelliJ IDE 2017.3.2 Maven Project packagingexcludes

I have a maven project that is going out to tomcat using a exploded war build in development. I have the following entry in my pom to exclude certain files for any non development environments:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>web</warSourceDirectory>
<failOnMissingWebXml>true</failOnMissingWebXml>
<webXml>web/WEB-INF/web.xml</webXml>
<packagingExcludes>
WEB-INF/classes/application.properties,
WEB-INF/classes/proxool.xml,
WEB-INF/classes/log4j.properties,
WEB-INF/classes/wetemplates/**
</packagingExcludes>
</configuration>
</plugin>
The packaging excludes are being used by intellij and excluded from my local development build and breaking it. I have been having to comment this block out in development for the environment to function correctly. How can I resolve this so that these are not excluded in my development environment?
You can use maven profiles to configure the build in such way that the Intellij build will use one given profile and the Maven/external build will use another profile.
Take a look at here: http://maven.apache.org/guides/introduction/introduction-to-profiles.html

Deploy maven project in to AEM?

I have created a maven project with content and bundle folder i can build the project successfully in eclipse
use this command :-
mvn clean install
but my bundle jar and content zip not reflecting in AEM now i am manually uploading the zip and jar in to AEM but i need to deploy directly from eclipse with out manual intall.
Can anybody help on this ?
install is a phase in the Maven lifecycle during which an artifact is installed in your local Maven repository.
It usually has nothing to do with installing anything in AEM. You need to use specific Maven plugins to achieve that.
If you generated your project based on the Adobe archetype, you need to specify, using a profile, that you want your app deployed.
mvn -PautoInstallPackage install
This profile activates the Maven Vault Plugin and uses it to upload the CRX package to AEM. Here's a snippet from Adobe's AEM archetype where this behaviour is defined.
<profile>
<id>autoInstallPackage</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>content-package-maven-plugin</artifactId>
<executions>
<execution>
<id>install-package</id>
<goals>
<goal>install</goal>
</goals>
<configuration>
<targetURL>http://${aem.host}:${aem.port}/crx/packmgr/service.jsp</targetURL>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
Check out the official documentation for more information.
If, by any chance, your project happens to be using the Maven CRX Plugin (Adobe's archetype and its particular choice of plugins is just one of the options available in the wider AEM community), you need to explicitly invoke the crx:install goal.
mvn install crx:install
The bottom line is, mvn install just takes care of installing artifacts in your local Maven repository. In order to deploy to AEM, you need to invoke something more or set up your project to activate some plugins automatically in a certain phase of the lifecycle.

Converting Eclipse dynamic web project to maven project with modules

so I just started a new project at work where I've gotten some code, really strange code...
So the project structure was as follows:
simple-java-project-1 ---> eclipse java project which holds some database-connectors
simple-java-project-2 ---> holds the logic of converting, formatting etc of the data, uses the connectors from project-1
dynamic-web-project --> just gets the jars from project1 and project2 and offer's a websocket api to send this data etc.
I would like to convert this mess to a well structured maven project. So I created a master maven project with this pom:
......bla bla bla....
<modules>
<module>the-connectors</module>
<module>the-logic</module>
<module>the-dynamic-web-module</module>
</modules>
<dependencies>.....</dependencies/>
And the modules as well. I added the dependencies needed to them.
So now the hard part I didn't get : How can I achive that the whole project is deployed to the local tomcat and runs?
The web.xml and /WEB-INF/ stuff is in the "the-dynamic-web-module" module for now,...
Any ideas or hints?Thanks in advance.
You should add the tomcat7-maven-plugin to your the-dynamic-web-module:
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/</path>
<uriEncoding>UTF-8</uriEncoding>
<systemProperties>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
After building and installing the 2 other modules (mvn install), go to the-dynamic-web-module and launch mvn tomcat7:run. Then with your browser, go to localhost:8080/ and you should get your app.

Categories