Installing JCOSap using maven on springboot - java

I have an issue when I use maven for installing an external jar from SAP.I'm using springboot and I've gotten 2 scenarios with no success.
1- Using maven dependency directly from folder I get an exception and the jar is not added in BOOT-INF/lib folder. But on eclipse the jar is added in Maven Dependency
<dependency>
<groupId>com.sap.conn.jco</groupId>
<artifactId>sapjco3</artifactId>
<version>3.0.19</version>
<scope>system</scope>
<systemPath>/home/eder/workspace/obsekium/TesteSelenium/sapjco3.jar</systemPath>
</dependency>
Caused by: java.lang.NoClassDefFoundError: com/sap/conn/jco/ext/DestinationDataProvider
2- Using "mvn install:install-file" Maven changes jar's name and it causes an exception
Factory method 'sapConector' threw exception; nested exception is java.lang.ExceptionInInitializerError: JCo initialization failed with java.lang.ExceptionInInitializerError: Illegal JCo archive "sapjco3-3.0.19-3.0.19.jar". It is not allowed to rename or repackage the original archive "sapjco3.jar".
How do I solve this issue?

You can try to use the following dependency and check whether it works.
<dependency>
<groupId>com.sap.jco</groupId>
<artifactId>sapjco</artifactId>
<version>3.0.14</version>
</dependency>
You can find the details from the following link.
https://mvnrepository.com/artifact/com.sap.jco/sapjco/3.0.14
If you want, you can download the jar file and you can set the dependency as system path in maven.

Related

java.lang.IllegalStateException: Failed to read Class-Path attribute from manifest of jar error using Selenium through Maven in Spring Boot

I have been running in to various issues while trying to configure selenium webdriver to test my spring boot application. Every time I put the selenium dependency in to my pom.xml it seems to corrupt my m2 repository, or that is what I think.
This is the dependency:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
This is the error message:
Exception in thread "main" java.lang.IllegalStateException: Failed to read Class-Path attribute from manifest of jar file:/C:/Users/Usuario/.m2/repository/commons-codec/commons-codec/1.11/commons-codec-1.11.jar
at org.springframework.boot.devtools.restart.ChangeableUrls.getUrlsFromClassPathOfJarManifestIfPossible(ChangeableUrls.java:132)
at org.springframework.boot.devtools.restart.ChangeableUrls.fromClassLoader(ChangeableUrls.java:98)
at org.springframework.boot.devtools.restart.DefaultRestartInitializer.getUrls(DefaultRestartInitializer.java:92)
at org.springframework.boot.devtools.restart.DefaultRestartInitializer.getInitialUrls(DefaultRestartInitializer.java:56)
at org.springframework.boot.devtools.restart.Restarter.<init>(Restarter.java:142)
at org.springframework.boot.devtools.restart.Restarter.initialize(Restarter.java:556)
at org.springframework.boot.devtools.restart.RestartApplicationListener.onApplicationStartingEvent(RestartApplicationListener.java:76)
at org.springframework.boot.devtools.restart.RestartApplicationListener.onApplicationEvent(RestartApplicationListener.java:50)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:69)
at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:48)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:302)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
at pe.backend.BackendApplication.main(BackendApplication.java:10)
I have tried cleaning my m2 repository various times and adding different versions of the dependency, but It doesn’t seem to solve it. I have also tried using clean install, but it shows a build error if I have put the selenium dependency.
This error message...
Exception in thread "main" java.lang.IllegalStateException: Failed to read Class-Path attribute from manifest of jar file:/C:/Users/Usuario/.m2/repository/commons-codec/commons-codec/1.11/commons-codec-1.11.jar
...implies that one of the jars in your maven cache corrupted.
In your case, it seems the the following file got corrupted:
file:/C:/Users/Usuario/.m2/repository/commons-codec/commons-codec/1.11/commons-codec-1.11.jar
Solution
You need to remove the specific jar from your maven cache and re-build your application.
As you have already tried cleaning the m2 repository various times through clean install but the error persists you may need to hard delete this particular jar and rebuild your application.
Outro
You can find a relevant discussion in:
Devtools startup exception

Logging system failed to initialize using configuration from 'classpath:logger/logback-spring.xml'

I use Spring boot 2.3.0.RELEASE.
application.properties
spring.profiles.active=dev
logging.config=classpath:logger/logback-spring.xml
logging.file.dir=reception-electronic-docs
logging.file.name.var=reception-electronic-docs.log
logging.file.archive.format.name=reception-electronic-docs.%d{dd-MM-yyyy}.log
Previously this code worked (Srping boot 2.2.5.RELEASE).
I use multi module structure in the project. But there, the Central pom does not manage the entire project. I create microservices.
During start up an application encounter an error:
Logging system failed to initialize using configuration from 'classpath:logger/logback-spring.xml'
java.io.FileNotFoundException: class path resource [logger/logback-spring.xml] cannot be resolved to URL because it does not exist
at org.springframework.util.ResourceUtils.getURL(ResourceUtils.java:137)
What are any ideas to correct this?
I add an dependencies
<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>janino</artifactId>
<version>3.1.2</version>
</dependency>
But I don't understand reason.
After I removed the dependency. But my app runs without errors. I'm at a loss.

(springboot) jar not executable on other computers

I have a spring Boot application. I package it with maven, and I execute it with java -jar xxx.jar. The application is running. However if I copy the jar on another machine (same java version, same OS) I get a dependency error:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name
'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration':...
...
Unsatisfied dependency expressed through constructor parameter 0
...
Bean instantiation via factory method failed
...
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [javax.sql.DataSource]:
Factory method 'dataSource' threw exception; nested exception is java.lang.NullPointerException
I added debug=true to show the classpath during execution, but it seems the same on both machines (there were issues with classpath order between maven execution and java execution)
EDIT: actually the problem is not changing machine: if I just move the jar in another folder, I get the same error. If I look at the correct running process it seems fairly obvious that in the classpath there are references to ther project target folder that cannot be satisfied...
Original machine is iOS, I tried the jar on other iOS and a Centos machine with same result.
I thought jar was very portable for deployment, so I don't understand if there is a better way of deploying the application or some environment variable I'm not taking into account
EDIT: I use maven. I do
mvn package
or
mvn clean install
and I have the dependencies mentioned in the answer
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
You need to create a Fat jar (a jar file with all the dependencies), you can find a more detailed info here, but to let some code in the answer:
Basically what you have to do is check that you have the right dependencies in your pom
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
</dependencies>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.1.RELEASE</version>
</plugin>
</plugins>
Then you should do
mvn clean install
And run it!
java -jar <artifact-name>
EDIT
What do you see if you do a repackage? mvn clean package spring-boot:repackage
Your HibernateJpaConfiguration bean cannot be created. It looks it has some property declared in a #Configuration annotated class or in the application.properties resource file. Some property that has a relative path in it, and when you move the jar it cannot find that property.
Actually it was a trivial issue: a directory had to be listed from a relative path and in order to execute the jar somewhere else I had to just create that directory.
The error wasn't properly catched so the stacktrace was showing failure in dependencies and I missed the simple reality: java.lang.NullPointerException....
Thanks to #AndyWilkinson for making me read the stacktrace again...

How do I use a Liquibase changelog which is in jar file

I currently have the following in my application.properties:
liquibase.change-log=classpath:/db/changelog/db.changelog-master.xml
The actual path to the file is src/main/resources/db/changelog/db.changelog-master.xml.
The changelog is found by Liquibase and everything is working as I would expect.
I've moved the changelog and all of the project's JPA entities and repositories into a separate project so that they can be shared with other projects.
This second project is a Maven dependency of the first project. What path do I need to use in application.properties of the first project to access the liquibase changelog in the second project?
Update
I have:
projectA.jar -> pom.xml
<dependency>
<groupId>com.foo</groupId>
<artifactId>projectB</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
projectA.jar -> application.properties
liquibase.change-log=classpath:/db/changelog/db.changelog-master.xml
projectB.jar -> src/main/resources/db/changelog/db.changelog-master.xml
But I'm getting:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration$LiquibaseConfiguration': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Cannot find changelog location: class path resource [db/changelog/db.changelog-master.xml] (please add changelog or check your Liquibase configuration)
I'm an idiot. My local ~/.m2 repository had an old version of the jar without the Liquibase changelog. A mvn clean install fixed the issue.

java.lang.NoSuchMethodError: javax.media.opengl.GLDrawableFactory.initSingleton()V

I am trying to use the JZY3D libraries in my Java project.
Starting with the basic, I set up the following main():
public static void main(final String[] args) {
new GLCapabilities(GLProfile.getDefault());
}
The jogl-all.jar, gluegen-rt.jar and gluegen.jar files are in the build path. I get the following exception:
Exception in thread "main" java.lang.NoSuchMethodError: javax.media.opengl.GLDrawableFactory.initSingleton()V
at javax.media.opengl.GLProfile.initProfilesForDefaultDevices(GLProfile.java:1444)
at javax.media.opengl.GLProfile.access$100(GLProfile.java:76)
at javax.media.opengl.GLProfile$1.run(GLProfile.java:174)
at java.security.AccessController.doPrivileged(Native Method)
at javax.media.opengl.GLProfile.initSingleton(GLProfile.java:140)
at javax.media.opengl.GLProfile.initSingleton(GLProfile.java:199)
at javax.media.opengl.GLProfile.getProfileMap(GLProfile.java:1914)
at javax.media.opengl.GLProfile.get(GLProfile.java:815)
at javax.media.opengl.GLProfile.getDefault(GLProfile.java:602)
at javax.media.opengl.GLProfile.getDefault(GLProfile.java:613)
at eu.crisis_economics.abm.model.SpecsCompetitionStrategyCFO.main(SpecsCompetitionStrategyCFO.java:312)
It seems like there is a problem with the 3d libraries, but I cannot figure out what.
The jogl-all.jar, gluegen-rt.jar and gluegen.jar files are in the build path. I get the following exception:
Remove gluegen.jar from the build path.
Make sure these two jars are added to the classpath at runtime as well!
You only need jogl-all.jar and gluegen-rt.jar (rt == runtime) at compile time and runtime.
Also you need to have a copy of the matching native jars gluegen-rt-natives-os.and.arch.jar and jogl-all-natives-os.and.arch.jar for the platform you use next to the gluegen-rt.jar and jogl-all.jar
http://jogamp.org/jogl/doc/deployment/JOGL-DEPLOYMENT.html#NativeJARFiles
Have you tried the Maven dependency instead of add those jars by hand?
I made a clean maven project, add a new user library with the following files:
org.jzy3d-0.9.jar
dependencies/misc/opencsv-2.1.jar
dependencies/misc/org.convexhull.jar
dependencies/misc/swt.jar
dependencies/misc/swt-debug.jar
After that, I add the following maven dependencies:
<dependency>
<groupId>org.jogamp.gluegen</groupId>
<artifactId>gluegen-rt-main</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.jogamp.jogl</groupId>
<artifactId>jogl-all-main</artifactId>
<version>2.0.2</version>
</dependency>
Build & Run with no exceptions.
A much cleaner solution is:
Clone Jzy3D repository (https://github.com/jzy3d/jzy3d-api)
install jzy3d-master
add the jzy3d-api dependency for your project

Categories

Resources