Jenkins meven Java Import working giving differnt path - java

I have a a java class looking for another project using an import.
import this.is.the.java.file.im.looking.for
I run off a pom.xml file using a maven build in eclipse and it's working fine using the m2e plugin. When i try to run it on jenkins using the maven integration plugin it says it can't find the file because it's looking into the same project folder instead of the dependency project.

Maven configured on jenkins also requires appropriate settings.xml to fetch dependencies it required. There might be possibility that due to inappropriate settings.xml file , maven won't be able to fetch dependencies.
Please make sure settings.xml at in jenkins installation directory e.g. /var/lib/jenkins for ubuntu.
also check whether settings.xml under .m2 folder in your jenkins installation directory.
and finally validate whether there is jar file fetched in local maven repository under .m2 directory.

Related

Java Maven -> quickls add folder of jars as depencency

my Java Project uses a "/libs" folder containing ~100 .jar files. Almost all of them are not in an official maven repository.
1.) In the moment I manually added to whole folder to the classpath with my Eclipse IDE. That enables to compile and run the App using the Eclipse IDE. But if I want to maven to compile and create jar-with-dependencies, maven of course does not know about the "/libs" folder.
2.) I know that I can add a jar file to my local maven repo with mvn install:install-file but this would take a very long time because I would also have to open every jar and find the whole package name to insert as '-DgroupId' and the Name of the Main Class to add as '-DartifactId'
3.) My Questions:
3.1) Is there an easy way to let maven just include all jars in a folder like I did with my Eclipse IDE? I know that would break the principle of maven that every jar is identified with group and artifact id, but it would be a quick solution.
3.2) If it is not possible to add a folder with jars as a dependency in maven, is there a faster way to add a jar file into a local repo. It would be easier if there is a maven command where groupId and artifactId are automatically discovered by the jar that I do not have to open every jar file and find the Main Class and its classpath
Quick answer: No.
In the past, I have written a script for that because there is not support in Maven for this.

Export jar with spring boot

I need to export executable jar from intellij spring boot project. its basic rest only. How can it possible. I have created the artifact jar and when i try to run it with java -jar xxx.jar it returns manifest file not found error.
Generally you have this error when you generate the JAR using the IDE directly (export option of Eclipse for example).
You can either use the Maven goals clean install or clean package to compile and generate the JAR in your target folder and/or local repository.
package - take the compiled code and package it in its distributable
format, such as a JAR.
install - install the package into the local repository, for use as a
dependency in other projects locally
The install will execute the package one step before install it on your local repository.
Maven Lifecycle Documentation
If you have installed maven, On the terminal of Intellij Idea use following code.
mvn clean package
Your Jar will be saved inside "target" folder inside the project directory

How to find and missing artifacts in a maven project using eclipse as editor?

I am working on a Maven project and I am using eclipse as an editor. I clone a project from GIT and then create a git repository in eclipse , import it and then create a maven project. After i finished the project of setup i got a lot of errors and this is due to pom.xml file and I am missing about 300 artifacts.I know want to know how can i find and add those artifacts in my project. I have seen different answers for that and one of the answers is to upload maven project. I did it but still not working , I am still missing the artifacts.
I really need some help here since i want to start working on this project as soon as possible.
Maven pulls all the dependencies either from maven repository or from local repository automatically (typically C:/Users/user1/.m2 on windows). if there are lot of dependencies, eclipse takes a while to download them all.
check if you see building workspace at the right bottom corner of eclipse. you can press Alt+F5 to refresh the project and then try command mvn clean install from your root folder (where your pom.xml is placed)
Sometimes, jars are not available on maven repository such as sqljdbc. in that case you will have to manually install them to your local repo using below command if you have the .jar file
mvn install:install-file -Dfile=<path-to-file>/stax-1.0.jar
-DgroupId=stax -DartifactId=stax -Dversion=1.0 -Dpackaging=jar
or a quick and dirty approach would be copy the .m2/repository folder from previous machine if project was working good on that machine.

Generate war file from existing maven project

I have downloaded a project from git. Its a web project using maven. I have eclipse in my machine and also maven is there. Now I want to create a war file from this project for deploying in Tomcat.
Any idea how I can do it. Command line will be a prefer option. I searched in Google but in most of the places it is asking to create a new Maven project or I am missing something.
Thank you
Just add <packaging>war</packaging> to your pom.xml, and run mvn package from the root of your project (i.e. where the pom.xml resides). If everything will be successful, you'll get a war file in the target directory. See: http://maven.apache.org/pom.html#Maven_Coordinates

Build the pom file to download the dependencies with eclipse

I download a j2ee project with a pom file which mention the dependency jar files needed. I want to know to run this pom file and download the jars need for my project? I right click and ran the pom file as maven build. Then it prompt me the Edit and Configuration UI which has the goals and profiles.
What are the values that i need to specify here?
Also is there any special configuration i need to add to eclipse (helios)?
How does the necessary jar files downloaded? Is it from the xsi:schemaLocation location specify in the pom file?
You can use these maven goals for that.
eclipse:eclipse - Download the dependency jars and set them to the classpath(you need to configure your settings.xml in the maven with the maven archiva repo path for maven to download jars from there)
install - build the project and install it in the local repo.
Have a look at this answer for the whole list of goals.
IF you install the Maven to Eclipse integration plugin (m2e), Eclipse will automagically add the project dependencies to the project's build path, and download them in the process.

Categories