There is a java project built with Maven. I have project sources, need to improve something and then rebuild the project.
The problem is one of Maven dependencies is now lost (seems like it was only in developer's local repo). But there is a compiled project (.ear). I suppose it has code from that Maven dependency.
Is there a way to build a project using old project's compiled files?
Extract the required jar from old ear, and in new pom add that jar as dependency,
<dependency>
<groupId>GroupId</groupId>
<artifactId>ArtifactId</artifactId>
<version>VersionNo</version>
<scope>system</scope>
<systemPath>path/to/the/jar</systemPath>
</dependency>
You can use the compiled jar's and put them into library folder and rebuild path.
Related
I'm trying to compile a multi-module maven project. I have problems to compile a new module I added. This problem arises because the new module is trying to import a pair of packages which exist in another module.
This is the pom.xml of the new module:
Here is the view in the eclipse's project explorer, where i highlighted the 2 packages I'm importing from the class ServicioJMS of the new module:
And here's the error showed in the command line after doing a mvn clean package
As you can see below I added the module in the parent pom.xml:
So, I don't know what I'm doing wrong here ¿Any ideas?
NOTE: Eclipse has no problem resolving the dependencies related to the discussed imports.
I had a similar problem. Go to the library on which you are depending (under your ~/.m2/repository directory or in the ./target directory of the library) and find the compiled library jar. Use jar -tf to list it and check that the missing classes are listed directly in the jar.
If you are using the spring boot maven plugin or similar in the library on which you are depending then it constructs a jar with a radically different structure and the classes, while being in there, will be hidden within the structure rather than being directly in the jar by name. Eclipse understands this, but the spring boot loader won't unpack the spring boot maven plugin structure of a library within a dependency, it will only do that for the runnable jar being executed.
If this is true for you then you can remove the offending build plugin from the pom of your library making it just a library, not a runnable spring boot jar.
A few things:
1) Don't put a version or group if you have a parent, let them be picked up from the parent.
2) When importing a dependency from a module under the same parent use ${project.version}
here's an example:
<parent>
<artifactId>parent</artifactId>
<groupId>com.essexboy</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>web</artifactId>
<dependencies>
<dependency>
<groupId>com.essexboy</groupId>
<artifactId>library</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
Use install instead of package because IntegradorTransformador artifact (jar) was created but not exists in m2 repository and IntegradorTransformadorReproceso project can't found the artifact
mvn clean install
I am trying to add the locally created project which contains JARs added using java build path to my maven project as dependency and the JARs used in the dependency project are also be useful in the main project. how to deal in this scenario if I don't want to convert my dependency project to maven?
You have different possibilities:
<dependency>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>2.53.1</version>
<scope>system</scope>
<systemPath>
C:/.../your-jar.jar
</systemPath>
</dependency>
or you can install it in your local .m2 repo
https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
This doesn't force you in any way to convert your project into a maven project, but let you reuse the jar you already have.
This is similar like Maven multimodule project. In that all the submodules gets added to the root project as a jar after successful compile. In your case try covert the project into jar and copy the same jar file to the lib folder of parent project.
I know there are post about JAVA libraries in Eclipse and I used a way to add some .jar files (like apache.poi and jsoup) to my project. My question is:
Where do we have to put those libraries and what settings do we have to change, so to make the libraries available for every future project we start ?
Thank you!
The most common tools for bringing dependencies into a Java project are Maven, Gradle, and Ant. I'll focus on Maven, as I estimate it to be the most popular of the three (though I have come to prefer Gradle).
I'm going to assume you have the following prerequisites installed on your machine and each of the developers on your team:
JDK 1.7 or above (in other words, Java)
A Java-focused IDE like IntelliJ or Eclipse
Here's what you need to do:
You and your team members will install Maven
You will create a pom.xml for each new project.
You will specify the dependencies for the project (like jsoup) in your pom.xml
Here's what Maven will do for you:
It will download all the dependencies you specify from an online repository like https://mvnrepository.com/
It will cache the dependencies in a directory in your user home folder called .m2 so that it doesn't need to download dependencies more than once per project
It will resolve the dependencies within each of your dependencies and avoid putting the same dependency on the classpath twice
The minimum pom.xml file you need is as follows:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.yourcompany</groupId>
<artifactId>your-project</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.8.3</version>
</dependency>
</dependencies>
</project>
Copy that into a file called pom.xml in your root project directory. You can add any additional dependencies in the <dependencies> section of the XML file. By convention, all of your classes and code should go into the directory structure src/main/java/.
Any Java IDE you use will know how to open a project from a pom.xml file. In IntelliJ, you select File->New->Project from existing sources, navigate to your project's root directory, select your pom.xml, and click Open. IntelliJ will then open your project as a Maven project, read your pom.xml, and make all of your dependencies indexed and available for code completion and compilation.
Hope this helps
I want to use cplex through a maven project. when I use cplex in a non-maven eclipse project, it runs correctly. in non-maven project I had to add the path to native library location of cplex in java build path.
but in the maven project, I get errors like "java.lang.NoClassDefFoundError: ilog/concert/IloNumExpr" at runtime.
I add dependencies to my cplex.jar in pom :
<dependency>
<groupId>cplex</groupId>
<artifactId>cplex</artifactId>
<version>2.0.1</version>
<scope>system</scope>
<systemPath>${basedir}\IBM.ILOG.CPLEX.Optimizer\cplex\lib\cplex.jar</systemPath>
</dependency>
and I test to add native libraries to src/main/resources, and adding resource tab in pom: it doesn't work. I add the native library to class path environment variable: it doesn't work. I copy them in c:/windows/system32: it doesn't work!
can any body help me? what is the solution? :-(
Just go through
How do I add a jar file to my local Maven repository using Eclipse m2e on Luna Service (4.4.1)?
basically if its a jar not available in maven repository, you can still add it to your local repository and with the required group id, artifact id, and other parameters and use the scope as system while referring to it from you pom file.
I have Android project A which refers Android library project B, Building Project A on eclipse works fine. But my app using some system API so I thought to build using maven. I am not getting how to include Project B in Project A on maven.
(basically proj B has both source and resource)
Basically I generated B.jar and edited pom file
<dependency>
<groupId>com.me.example</groupId>
<artifactId>myId</artifactId>
<version>2.4.1</version>
<type>lib</type>
</dependency>
then I am able to build A.apk but when I launch A.apk application, its crashing. Because project B has some resources and when I generate B.jar it has only class files and don't have resources. And also I tried to generate B.apk and included included in maven and I couldn't able to build A.apk.
How can I solve this.
First I built B.apklib then I included it in A project as dependency and now I am able to build A.apk
B.pom contains
<groupId>com.mer</groupId>
<artifactId>me</artifactId>
<version>1.4.3</version>
<packaging>apklib</packaging>
<name>I_am</name>
<dependencies>
.......
</dependencies>