I am able to create an object for a class in a jar file, which is another module.
I created a new java project with a main class, added the jar to the lib folder and I am able to create the object for that jar's class(com.canonical.client), while running the main class as a java application.
Now, I have converted this java project to maven. While I try to clean and install, I am unable to build successfully. The error given is " package com.canonical.client does not exist".
After Jespers's suggestion I am able to build the project. I am getting the following exception, while calling method which creates client object. In that jar, it looks for some other jars.
java.lang.ClassNotFoundException: ch.qos.logback.core.Context
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at com.mmf.controllers.PickEquifaxController.handleRequestInternal(com.mmf.controllers.PickEquifaxController:33)
My manifest file's first 2 lines in that jar are as follows, its refering 118 jars actually,
Manifest-Version: 1.0
Class-Path: . canonicalclient_lib/activemq-camel-5.8.0.jar canonicalclient_lib/activemq-core-5.6.0.jar
canonicalclient_lib/activemq-pool-5.6.0.jar canonicalclient_lib/activemq-protobuf-1.1.jar
What I need to do to get a solution in this. pls advice.
You can install your JAR in your local Maven repository with a command like this:
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id>
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
where you'll have to fill in your own group id, artifact id, version and packaging - the packaging will most likely be jar - for example:
mvn install:install-file -Dfile=myjarfile.jar -DgroupId=com.canonical
-DartifactId=client -Dversion=1.0 -Dpackaging=jar
After doing this, you can use it like any other Maven dependency, by specifying the dependency using the group id, artifact id and version in your pom.xml:
<dependency>
<groupId>com.canonical</groupId>
<artifactId>client</artifactId>
<version>1.0</version>
</dependency>
You can add your custom jar by this way in POM.xml
<dependency>
<groupId>com.canonicalclient</groupId>
<artifactId>xxx</artifactId>
<version></version>
<systemPath>${basedir}/lib/xxx.jar</systemPath>
</dependency>
Related
I am new to java and maven. I am learning and trying to make a system to help me build up JSON data by GOOGLE's gson and maven. This is my using command order:
mvn -f my-app\pom xml clean compile
mvn -f my-app\pom xml install
cd my-app\target
java -jar my-app-1.0.jar
After I run it it show me this error.
in GSONExample.java Line 13:
Gson gson = new Gson();
The following is my using software/IDE version.
Source Editor: VS Code
JDK: JDK-19
apache-maven: 3.8.6
Gson: 2.10 (https://github.com/google/gson/releases)
I have already gone through other websites and StackOverflow to find solutions.
GSON is not being imported into the maven project Changed scope role and still crash
error even though it is defined in my classpath /WEB-INF/lib can't find in my situation
Now below a part of my pom.xml
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10</version>
</dependency>
I also had try to import it(Gson) to local and try to fix it out.
mvn install:install-file -Dfile=C:\gson-2.10.jar -DgroupId=com.myself.gson -DartifactId=example-gson -Dversion=2.10 -f my-app\pom.xml
After I use the command, I changed pom.xml as follow. It can compile and install. But still show me "NoClassDefFound"
<dependency>
<groupId>com.myself.gson</groupId>
<artifactId>example-gson</artifactId>
<version>2.10</version>
</dependency>
May anyone provide any solution to this? Thanks in advance.
I had tried
changed scope to provided in pom.xml
put Gson in src\main\resources\lib and change pom.xml
Local gson-2.10.jar and change pom.xml
put gson-2.10.jar in C:\Program Files\apache-maven-3.8.6\lib
The problem is this command:
java -jar my-app-1.0.jar
Most likely your current Maven pom.xml creates a JAR file which contains only the classes of your project, but not the classes of dependencies, such as Gson. This is also not specific to Gson but applies to any dependencies you are trying to use. You can either:
use java -cp and specify the path to your JAR as well as the paths to all the JARs of dependencies you are using, for example java -cp gson-2.10.jar;my-app-1.0.jar com.mycompany.app.GSONExample
configure Maven to build a "JAR with dependencies", see this question whose answers describe multiple ways of how this can be achieved
We are using Jenkins maven plugin for building and deploying war applications. In the jenkinsfile we have the command (I removed the list of profiles for the sake of simplicity):
mvn release:clean release:prepare -P<profiles> -U -DautoVersionSubmodules="true" -Darguments="-T 1C -DskipTests=true" -V --batch-mode --errors
The built war artifact has MANIFEST.MF file with field Release-Name set to main.
Release-Name: main
In the parent pom.xml there are some extra settings for customize MANIFEST.MF but it seems to me that "Release-Name" is added by default because it is not listed below:
<manifestEntries>
<Version>${project.version}</Version>
<Revision-Number>${buildNumber}</Revision-Number>
<Branch>${GIT_BRANCH}</Branch>
<Local-Branch>${scmBranch}</Local-Branch>
</manifestEntries>
So I tried to look into the maven release plugin source code from this repository but I couldn't find anything helpful.
Then the main question is how the field "Release-Name" is filled because I'd like to change it into some more meaningful value.
The problem, as it turned out, was in another module of the project, which was downloaded from remote repository, while building the entire artifact. In this extra module, there was a definition in pom used to set the value of Release-Name in the manifestEntries section.
<Release-Name>${releaseName}</Release-Name>
I have my own maven project:
/path/to/my_project/
pom.xml
/src/main/java/com/my/MyProject.java
MyProject.java contains a dependency to external class:
package com.my;
import com.other.ExternalClass;
class MyProject {
ExternalClass d;
}
External class is located in another maven project:
/path/to/another_project/
pom.xml
/src/main/java/com/other/ExternalClass.java
How to specify dependency such that mvn install command executed on my project would not throw error package com.other does not exist
You mvn install the project another_project
You add a <dependency> entry with the correct coordinates (groupId, artifactId, version) of another_project to the pom.xml of my_project.
Then you mvn install the project my_project.
I want to build one jar that includes a child module which depends on other package of my own project.
The output one jar should include all the related class (both from jar and my own project's classes).So the child module's classes is the base classes that should be included in the output jar,and these import some classes of my own project.All the related classes in my own project should be included.
for more detail please visit How to automatically collect all related class into one jar (use maven)?
Here is what I already find:
<project>
<dependencies>
<dependency>
<scope>system</scope>
<systemPath>D:\how\to\write</systemPath>
<groupId>how.to.write</groupId>
<artifactId>how-to-write</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>java-source</type>
</dependency>
</dependencies>
</project>
The error message is : Could not find artifact how.to.write:how-to-write:jar:sources:0.0.1-SNAPSHOT at specified path D:\how\to\write
the path D:\how\to\write contains my own project's classes that could support the build
Your maven dependency will look for a jar file with name how.to.write:how-to-write:jar:sources:0.0.1-SNAPSHOT in D:\how\to\write directory. Since you do not have one, the build will fail.
If your own project does not use maven, then you should create a jar file and place it in D:\how\to\write location and rename it to how.to.write:how-to-write:jar:sources:0.0.1-SNAPSHOT. Then your build mvn clean install will be success.
The command for creating jar file is jar cf jar-file input-file(s).
Have a look at this page on how to create a jar file
Could you please help me to find Dependency tag for rs2xml.jar. i think it is really helpful for me. net.proteanit.sql.DbUtils
I checked the Maven Central Repository as well as the MvnRepository for the rs2xml JAR file and could not find it. A Google search for a POM corresponding to this dependency also came up empty. However, you can still manually install the JAR into your own local repository and then use it as if it were any other dependency.
mvn install:install-file -Dfile=C:\rs2xml.jar -DgroupId=net.proteanit.sql
-DartifactId=rs2xml -Dversion=1.0 -Dpackaging=jar
Replace the path C:\rs2xml.jar with the actual location on your computer where you downloaded the JAR. To use the rs2xml dependency in your project, include the following tag in your POM file:
<dependency>
<groupId>net.proteanit.sql</groupId>
<artifactId>rs2xml</artifactId>
<version>1.0</version>
</dependency>
I have to extracrt the package:
net.proteanit.sql.DbUtils
to import im my project.
It's works!
Before I tried to edit pom.xml with the sugestion :
<dependency>
<groupId>net.proteanit.sql</groupId>
<artifactId>rs2xml</artifactId>
<version>1.0</version>
But doesn't works... :(
https://github.com/wfrsilva/javaMySQL03_infoX