NoClassDefFoundError when running local tests with only tenant-scp-neo included in POM - s4sdk

Motivated by this blog entry, I tried to implement multitenancy for our existing application on the classic SAP Neo SCP.
I added the dependency
<dependency>
<groupId>com.sap.cloud.s4hana.cloudplatform</groupId>
<artifactId>tenant-scp-neo</artifactId>
<version>1.9.5</version>
</dependency>
to my POM and accessed the tenant in a test program via
String tenantId = TenantAccessor.getCurrentTenant().getTenantId();
Then, I got this error
java.lang.NoClassDefFoundError: com/google/common/collect/Multiset
at com.sap.cloud.sdk.cloudplatform.monitoring.ExceptionMonitor.<init>(ExceptionMonitor.java:30) ~[core-1.9.5.jar:na]
at com.sap.cloud.sdk.cloudplatform.monitoring.ExceptionMonitor.<clinit>(ExceptionMonitor.java:28) ~[core-1.9.5.jar:na]
at com.sap.cloud.sdk.cloudplatform.logging.CloudLoggerFactory$CloudLogger.<init>(CloudLoggerFactory.java:67) ~[core-1.9.5.jar:na]
at com.sap.cloud.sdk.cloudplatform.logging.CloudLoggerFactory$CloudLogger.<init>(CloudLoggerFactory.java:47) ~[core-1.9.5.jar:na]
at com.sap.cloud.sdk.cloudplatform.logging.CloudLoggerFactory.getLogger(CloudLoggerFactory.java:19) ~[core-1.9.5.jar:na]
at com.sap.cloud.sdk.cloudplatform.tenant.ScpNeoTenantFacade.<clinit>(ScpNeoTenantFacade.java:21) ~[tenant-scp-neo-1.9.5.jar:na]
How can I solve this issue?

After some investigation, it seems that the issue was a corrupt guava jar file in the Maven repository (within the .m2 folder). Deleting the respective folders and having Maven download them again fixed the issue.

Related

How to add external jars in/with Maven WITHOUT installing locally

Currently the way I'm referencing my Jars through my Spring Boot application is by using Maven dependency manager with a system path.
<dependency>
<groupId>example1.1</groupId>
<artifactId>example1.1</artifactId>
<version>1.1</version>
<scope>system</scope>
<systemPath>${basedir}/libs/example1.1.jar</systemPath>
</dependency>
... etc (30 more jars)
How would one avoid this way of loading of jars since I'm moving over to to publishing it as a jar and getting a error of:
should not point at files within the project directory,
${basedir}/libs/example1.1.jar will be unresolvable by dependent
projects
Any easy way to load multiple jars without putting them on the local system?
Cheers

Dependency listed in pom file not found in deployed project

I asked a question here that I think I may have found the root of. I have a Spring Boot app using a datasource, net.sourceforge.jtds.jdbc.Driver, that is supposed to be included transitively by Spring Boot 2.0.2 with spring-boot-starter-jpa. However, when I run
jar tf my.jar | grep jtds
the driver class isn't found (we don't have a maven executable on the server to list the classpath). Everything I do to inspect the classpath reflects that the jar isn't there.
I've done this in 2 scenarios: 1) When I didn't explicitly add the jar to my pom, I got the error reported in my previous post. 2) When I do add it explicitly to the pom, I get this error:
java.lang.IllegalStateException: Cannot load driver class: net.sourceforge.jtds.jdbc.Driver
Can someone tell me what's going on?? I am confounded as to why this class can't be found and loaded.
Please mind, that in the Spring Boot Parent POM the jtds dependency is only included in test scope.
If you want to use classes of this dependency also in your production code, please change the Maven scope to compile.
Ok, the problem was solved by adding the dependency with a runtime scope.
In child pom where jar is packaged, you should have
spring-boot-maven-plugin. and dependency as below:
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
</dependency>
In parent pom :
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>${jtds.version}</version>
</dependency>

selenium-central-framework in pom.xml

I am not able to find any hint about the issue that I am facing and hence posting my question here. Please apologize if it is something silly.
I have some working experience in selenium webdriver. However in my new project, I was asked to use an existing Selenium framework.
In the pom.xml, I am seeing the below dependency (I have edited xxx to avoid displaying the company name)
<dependencies>
<dependency>
<groupId>com.xxxqa.selenium</groupId>
<artifactId>selenium-central-framework</artifactId>
<version>2.0.18</version>
</dependency>
Question :
I couldn't understand from where that dependancy was taken from ?
Solution Tried :
I have tried searching in the maven repository still couldn't find
anything related to "selenium-central-framework"
I have checked the dependencies of selenium RC, but they seems to be different from the one that is present above.
I have researched whether any local jars were used and were linked
as dependancy. However I understand from maven repository, local
repositories will be linked with the tag "systemPath"
<dependency>
<groupId>ldapjdk</groupId>
<artifactId>ldapjdk</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${basedir}\src\lib\ldapjdk.jar</systemPath>
</dependency>
</dependencies>
Note that the depedency used in my project doesn't have the tag "systemPath".
Is there anyway the external repositories could be added without mentioning systemPath ??
Please help, what could be that dependency ? How to find more information about it. Thanks a ton for your help.
I suggest you one of these approaches:
Jar file
If you have access to the jar file called : selenium-central-framework-2.0.18.jar, open a command line pointing to the folder of this jar and execute:
mvn install:install-file \
-Dfile=selenium-central-framework-2.0.18.jar \
-DgroupId=com.xxxqa.selenium \
-DartifactId=selenium-central-framework \
-Dversion=2.0.18 -Dpackaging=jar
Source code file
If you have the source code of : selenium-central-framework-2.0.18.jar, open a command line pointing to the folder of this source code and execute:
mvn clean install
After one of these approaches, selenium-central-framework-2.0.18.jar will be available in you local maven repository ($HOME/.m2) and your other java maven projects will be ready to use it as dependency:
<dependency>
<groupId>com.xxxqa.selenium</groupId>
<artifactId>selenium-central-framework</artifactId>
<version>2.0.18</version>
</dependency>
This is a workaround if you don't have a server to host an artifact repository management server like :
https://www.sonatype.com/nexus-repository-sonatype
https://www.jfrog.com/confluence/display/RTF/Maven+Repository
Explanation
Almost all free, public, safe, useful and cool java libraries are hosted in https://mvnrepository.com . So any person in the world can use it in their maven project with this piece in their pom.xml:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
But in some cases, publish your source code to https://mvnrepository.com is not an option:
Oracle Driver. This driver (.jar) can only be downloaded from the official Oracle page. Private source code like IBM, Microsfot,etc
Source code of your company that should not be public.
Some super cool library that is only in github but not in the maven central repository.
So in this cases, the best and scalable solution is host and configure some artifact repository management server like :
https://www.sonatype.com/nexus-repository-sonatype
https://www.jfrog.com/confluence/display/RTF/Maven+Repository
This platforms are an emulation of https://mvnrepository.com . So with a minimal configuration:
You can host your special or private jars
Your maven projects could use this jars with the standrad xml dependency in pom.xml.
If you don't have a server to implement one of these platforms, the previous approaches could help you and get the same results

maven not adding dependency in WEB-INF/lib

I have a maven project B which is packaged as a war B.war and has a 'local' dependency A.jar. The pom for building A.jar has a dependency on restFB and it resolves properly while compiling.
<dependency>
<groupId>com.restfb</groupId>
<artifactId>restfb</artifactId>
<version>${com.restfb-version}</version>
</dependency>
However when I package B.war, restFB's jar is not present in the WEB-INF/lib directory of B.war and execution throws NoClassDefFoundError. What is also baffling is that I find this happening only when I build it on an AWS Amazon Linux and not while building on Ubuntu. There are similar questions in SO which suggest adding
<packaging>war</packaging>
which I already have but doesn't seem to solve the problem. Any ideas how to solve this?
It should be simple to understand, that you might have invoke locally under Ubuntu
mvn install
for A. Therefore it is in the local .m2 repository.
Did AWS Amazon Linux also have this artifact in its repository? If not, copy it there and try to package again.
Also you explicitly include and exclude certain artifacts within the build configuration for maven-war-plugin

ReflectionToStringBuilder errors in Maven Project

Some of my Roo generated .aj files seem to be generating errors as below. I can see commons-lang3-3.1.jar in my Maven Dependencies. I have added this to my pom.xml
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.1</version>
</dependency>
Failed to execute goal
org.codehaus.mojo:aspectj-maven-plugin:1.2:compile (default) on
project AdminDirect-Model: Compiler errors : [ERROR] error at return
ReflectionToStringBuilder.toString(this,
ToStringStyle.SHORT_PREFIX_STYLE);
I have a multi-module project, and when in STS I try to do a right click and Update Project, I get another annoying error saying "Problems Encountered while setting project description"...although this is probably a separate issue.
As an aside if anyone knows of the correct workflow to create a multi-module spring roo, JSF, JPA application (Model and Web tier under a parent module) that would be greatly appreciated.
I deleted the .m2/repository folder contents and forced a fresh download using Maven Update Project and then forced a refresh of snapshots. Seems to work, jars must have been corrupt?
tomcat server fails to start the server and application in STS

Resources