Maven dependency jar with prefix folder - java

My project pom.xml has a dependency to a 3rd party JAR file:
<dependencies>
<dependency>
<groupId>com.xyz.plugin</groupId>
<artifactId>abc</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
When I compile my project, maven fails to locate classes in this JAR file. This JAR file is structured as follows:
classes
|__com
|__xyz
|__plugin
|__<classes>
The compilation failed because this 3rd party JAR file has their classes com.xyz.plugin.* located inside the "classes" folder, instead of having the "com" folder at the top most level. Their MANIFEST file also does not include any classpath specified either.
Is there anyway I can write my pom.xml differently such that compilation will be able to locate the classes correctly within this 3rd party JAR? Thanks for any help!

Related

zookeeper jar in $HOME/.ivy2/jars for java application

My application is failing because of the following issue :
Source '/.../.ivy2/jars/org.apache.zookeeper_zookeeper-3.4.6.jar' does not exist
But I see, there exists a jar in that folder with "tests" suffix - org.apache.zookeeper_zookeeper-3.4.6-tests.jar
If I remove -tests from the name manually, the application runs fine.
I need to understand how can I place the jar my application is expecting in .ivy folder through my program/dependency.
Also, when are the all jars loaded in .ivy/jars folder, is it during the build?
I am using java with maven.
<!-- https://mvnrepository.com/artifact/org.apache.zookeeper/zookeeper -->
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.6</version>
<type>pom</type>
</dependency>
add this to your maven dependencies also the org.apache.zookeeper_zookeeper-3.4.6-tests.jar is for the test environment.

Cucumber without Maven

We are not Maven yet, and I’m trying to run a cucumber feature. Getting the below error.
java.lang.NoClassDefFoundError: org.picocontainer.PicoBuilder at
cucumber.runtime.java.picocontainer.PicoFactory.start(PicoFactory.java:17)
Below is my folder structure for src.
src
test.java.stepdefinition.holiday
Myholiday_StepDef.java
MyRunner.java
test.resources.features
holiday.feature
Add Jar file of “PicoContainer Core” to build path of your project if you are using java project.
You can use maven dependency for “PicoContainer Core” to your pom.xml (for Maven project) as mentioned below.
<dependency>
<groupId>org.picocontainer</groupId>
<artifactId>picocontainer</artifactId>
<version>2.14.1</version>
</dependency>

Adding dependent project's properties file to the build target folder in Maven

I'm new to Maven, have looked for some help with my problem but couldn't find a proper solution.
I have a main project in Maven, which has a dependency to my second project:
<dependency>
<groupId>a.b.c</groupId>
<artifactId>childproject</artifactId>
<version>1.1</version>
</dependency>
Both projects have their properties files: mainproject.properties, childproject.properties.
When I deploy the main project, childproject.jar goes to \lib folder, along with all other dependencies. But the childproject.properties is "build into" the childproject.jar. If I place another childproject.properties file next to mainproject.properties in \configuration folder, it is seen and used.
What could I do so Maven places childproject.properties automatically in the \configuration folder?
childproject.properties
pom mainproject has :
<dependency>
<groupId>a.b.c</groupId>
<artifactId>childproject</artifactId>
<version>1.1</version>
</dependency>
And add file in :
mainproject
/src/main/resources/mainproject.properties
childproject , add file in:
childproject
/src/main/resources/childproject.properties
When you deploy the main project => childproject.jar contain in classpath childproject.properties
You do not need to create a directory 'configuration' for the project 'mainproject' uses 'childproject.properties'.

Include Maven Project into NON-MAVEN Dynamic Web Application

I've included the Maven based project into my application, added Deployment Assembly which shows that the .jar file gets copied to WEB-INF/lib/ImportedProject.jar.
Problem occurs when imported lib wants to reference the lib that it is using which, apparently, does not get included inside the ImportedProject.jar.
Example:
ImportedProject pom.xml has:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.12</version>
</dependency>
When I add ImportedProject.jar to my Non-Maven project and run it, I get exception:
threw exception [Servlet execution threw an exception] with root cause
java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
My question is: How to add both that Maven project and its dependencies?
maven dependency plugin helps to get required project library with it's dependencies.
So, If you would like to add POM based project on NON-POM based project, all you would do is to execute mvn dependency:copy-dependencies command and you will have all dependencies on target/dependencies folder. Copy all jar from dependencies and paste to WEB-INF/lib directory.

Java Maven-Spring Web Project - Separating Dependencies into Jar o War

I'm brand new in Maven. I'm working with Spring-Maven project, it generates a WAR file with 95Mb of dependencies (JARs) and 5Mb of my code.
There is anyway to separate code and libs? packaging my code into WAR and all dependencies into other WAR/Jar?.
Im deploying my app in tomcat server.
Thank you in advance!
You can exclude selected dependencies in the WAR by specifying scope as provided in your pom.
For example:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
Just make sure your dependencies are available in the classpath. You can put them in shared lib directory in server.
For example, in tomcat it's /lib directory.

Categories

Resources