Building a Spring-Boot Maven project with Matlab Java API dependency - java

I am building a spring boot application and using Maven for the dependencies. I need to run some Matlab code from Java and I found out that MathWorks made an official Java API available to use since 2017. But the official documentation for it only points to a .jar file inside installed Matlab folder and does not have any Maven dependency. So how do I add it to my project in a smart way then? Right now I just do it in my pom.xml like this:
<dependency>
<groupId>com.sample</groupId>
<artifactId>sample</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/yourJar.jar</systemPath>
</dependency>
But it seems to be a deprecated feature in Spring-Boot.

Related

Java Library's Parameter Name differs between projects

I am developing Web Services with the following stacks:
Spring Boot with Spring Security
Maven -> add dependency from Maven Repo on pom.xml
Vs Code
Two Project (Two VS Code Windows): Production Development & Testing
List item
Desc:
In using 'SessionRegistry', when I try to see what is inside the 'SessionRegistry.class', the name of the parameters are as the image below:
Problem
Image_1.1) shows no indication on the purpose of the parameter as encircled on the image on the production project.
Stats on Testing Project, and this is my actual Expectation:
Expectation Image_1.2) has appropriate name of the parameter and it shows sense what is the purpose of the parameter.
++ Both of the Project is referring the same dependency thru pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
What I have already tried:
I have even tried to remove and download all of the dependencies at the Users/../.m2/repository
Wondered if the outdated version was the cause... so even tried to indicate the latest version enumerated on official maven repository website with the follwoing version:
--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.6.3</version>
</dependency>
Awaiting for your advise with an advance grafulness.
You have not provided the source code for the library. Without the source, the IDE will still show the prototype (since that can be determined from the .class file) but it will make up names for the arguments, as you see.
Refer to the VSCode documentation to learn how to attach source jars.

Spring, Maven: Correct the classpath of your application

I am trying to create a maven version of the gradle-based treehouse 'unit-testing-a-spring-application' project used in this course. See course code here.
After not being able to build initially, I ended up adding dependency versions specified in the original gradle build file. Maven will build fine, but running the app gives this:
The following method did not exist:
org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)
Ljava/lang/String;
The method's class, org.springframework.data.repository.config.RepositoryConfigurationSource, is
available from the following locations:
jar:file:/C:/Users/home/.m2/repository/org/springframework/data/spring-data-
commons/2.1.6.RELEASE/spring-data-commons-2.1.6.RELEASE.jar!/org/springframework/data/repository/config/RepositoryConfigurationSource.class
It was loaded from the following location:
file:/C:/Users/home/.m2/repository/org/springframework/data/spring-data-commons/2.1.6.RELEASE/spring-
data-commons-2.1.6.RELEASE.jar
Action
Correct the classpath of your application so that it contains a single, compatible version of
org.springframework.data.repository.config.RepositoryConfigurationSource.
Several similar problems are solved here on S.O. by changing the version of some related dependency. I have tried various versions of the following to no avail (I stick normally with spring-boot-starter-parent v2.1.4 cause it works all the time with my projects):
spring-data-commons
spring-boot-starter-parent
I see the needed class below listed in my project Dependencies directory, but what dependency versions will work in this case? How can I solve this otherwise?
org/springframework/data/repository/config/RepositoryConfigurationSource.class
I looked at your code and found some mistakes. Since your project is a spring-boot one, you mustn't add direct spring dependencies in your pom file. Instead try to use spring-boot based dependencies. For instance, instead of having such this dependency:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.9.2.RELEASE</version>
</dependency>
You must have the following one in your pom file.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

javax.jnlp as maven dependency

Using JNLP (javax.jnlp) in one java project, I reaized that it is not part of the normal JDK.
As it is a Maven project I would like to add it as a dependency to my POM.
The one dependency I found working is:
<dependency>
<groupId>javax.jnlp</groupId>
<artifactId>jnlp-api</artifactId>
<version>8.0</version>
<scope>system</scope>
<systemPath>${java.home}/lib/javaws.jar</systemPath>
</dependency>
But depending on a system path looks bad to me - really bad.
system is marked as deprecated here: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
Is there no other way?
Getting it from repositories as an reasonable up to date version (java 8)?
Or what would be the clean way?

using spring boot in a maven project

I am starting a new project with maven and spring boot and got problems already at the very beginning :-) Finally it works now, but I would like to know what I did wrong:
I simply wanted to add spring boot to my project by adding the maven dependencies:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-build</artifactId>
<version>1.5.9.RELEASE</version>
</dependency>
which can be found in Maven-Central.
This doesn't work.
Then I found out, that the correct dependency is without "-build":
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>1.5.9.RELEASE</version>
</dependency>
I would like to understand, where is the problem:
Do I get the info on the wrong place and maven central is wrong ?
Or why did I get problems from beginning. What is the correct aproach ?
I think one of the best approaches for creating new SpringBoot projects is to use the Spring Initilizr: https://start.spring.io/. With this tool you will get a generated .zip file which containts the basic maven/gradle folder structure and has the correct dependencies in your pom.xml or build.gradle file. During the creation of the .zip you can easily search for you required SpringBoot dependencies like Web or Security and with a tick in the checkbox will get you the right dependency.
You can also use a Plugin for Eclipse called Spring Tool Suite which enables you to create fresh SpringBoot project out of eclipse with rightclick -> New -> New Spring Starter Project. This is also available in IntelliJ or you use the dedicated IDEA STS from Eclipse https://spring.io/tools/sts/all

add cxf jar file in maven project?

I need to add cxf-core, cxf-frontend ext. file in the project. I am trying to add these using maven dependency in pom.xml but it didn't work and version number is getting be red when it is added.
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-core</artifactId>
<version>2.6.2</version>
</dependency>
org.apache.cxf:cxf-rt-core:2.6.2 not found.
I also tried to add using external .jar libraries. The IDE is Intellij IDEA.
2.6.2 worked for me, I used Eclipse to create a new maven project and pasted in your dependency. It worked, fetched the required jars and give me this dependency hierarchy.

Categories