difference between com.sun.jna and net.java.dev.jna? - java

I'm looking through the central maven repository and seeing a net.java.dev.jna and a com.sun.jna groupId for JNA. The github for JNA, using the com.sun.jna path as the directories in their source code, indicates that 4.1 has been pushed into the repository as part of a comment, but I'm seeing net.java.dev.jna at 4.1 and com.sun.jna at 3.0.
Obviously, I want to use JNA, but am baffled. What's going on with this package?

The correct 4.1 version to use is net.java.dev.jna:
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.1.0</version>
</dependency>
The package name still seems to be com.sun.jna, but if you look in the POM file, the Maven coordinates have become net.java.dev.jna:jna.
They seem to have been that way for quite a long time, based on the MVN respository results.

Related

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>

Why does Bintray Maven dependency snippet to copy include <type>pom</type>

I just spend all day trying to figure out why I was not able to include FontawesomeFX to my Maven project. It turns out that the dependency to copy includes an extra line that prevented my maven eclipse project from downloading the dependency.
So why is <type>pom</type> included?
So why is <type>pom</type> included?
Perhaps an unsatisfying answer, but this looks like a bug in Bintray. The artifact is not of type pom, and the suggested syntax appears to be wrong. (The suggested Ivy snippet makes the same mistake.)
JFrog do not appear to have a public issue tracker to report this without a support contract, but they suggest using the artifactory tag.
For comparison, the Central Repository shows the correct form:
<dependency>
<groupId>de.jensd</groupId>
<artifactId>fontawesomefx</artifactId>
<version>8.9</version>
</dependency>
but doesn't include versions since 8.10.

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?

Maven dependency for javax.ejb.jar into .m2 directory

I cant find javax.ejb.jar in my .m2 dirctory, I need this jar for import javax.ejb.Schedule; , here is my pom file entry.
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
I am not sure if it will work or not, or its a right way to do things. Can some one please help to make a change in the POM file so that it downloads javax.ejb.jar into the .m2 directory.
Updated
by .m2 I mean in the repository directory in the correct folder
hierarchy (What ever it is).
Why? We have multiple sub projects (In eclipse workspace), In order to resolve dependency we use M2_REPO/path/to/the/required_library_file.jar, Now theses projects are part of code bases, Every developer download the source code, Maven download all jar to the repository directory(of the developer using any OS/Platform). This relative path from M2_REPO helps developer to have consitenat code (for eclipse project). Otherwise everyone will be adding their own path.
If it still doesn't make sense, here is what I want, Please give me an entry for POM file which download the javax.ejb.jar file into .m2 directory what ever the sub path is.
I have to include this jar in every project manually (And every developer needs to them as well from what ever directory have glassfish (C: , D:, E:, or /home/glassfish/modules/)
D:\servers\glassfish-3.1.2\glassfish3\glassfish\modules\javax.ejb.jar
where rest of the jars in each project are included as M2_REPO/path/to/jar which makes less no changes in the code base to commit.
M2_REPO/javax/ejb/ejb-api/3.0/ejb-api-3.0.jar
M2_REPO/javax/enterprise/cdi-api/1.0-SP1/cdi-api-1.0-SP1.jar
M2_REPO/javax/inject/javax.inject/1/javax.inject-1.jar
etc etc
I think I hear what you mean now :)
The maven dependency you specify
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
which you have in .m2/repository/javax/ueb/ejb-api/3.0/ejb-api-3.0.jar does not contain the class/interface javax.ejb.Schedule.
But you found the jar-file in your glassfish server, which does contain javax.ejb.Scheduleand its name is D:\servers\glassfish-3.1.2\glassfish3\glassfish\modules\javax.ejb.jar and now you ask how to get that into the pom?
Well, the Java EE APIs and their official jars in maven are somewhat a study in disharmony.
If you run a search on maven central you will find multiple jars containing exactly that class. You will probably note that all appserver vendors provide their own edition of every aspect of every api in every version.
You should be able to find a jar with the javax.ejb module from glassfish in version 3.1.2
http://search.maven.org/#artifactdetails|org.glassfish|javax.ejb|3.1.2|jar
in which case the dependency would be
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.ejb</artifactId>
<version>3.1.2</version>
<scope>provided</scope>
</dependency>
I found another artifactId here, though maven has your version too.
A (very) weird maven caching problem? Then it might work tomorrow.
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>javax.ejb-api</artifactId>
<version>3.2</version>
</dependency>
Though this is a new version, for compilation it should do.
You may need to provide the repository location in your pom.xml file or in .m2/settings.xml file for the required jar to get downloaded into .m2 directory.
The dependency is declared as provided what means that the container will provide it.
What container are you using? I think Tomcat/Jetty won't provide that jar as it seems so Java EE. In that case just change the scope to compile.
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<version>3.0</version>
<scope>compile</scope>
</dependency>
More info about dependency scopes:
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope

How to add Spring libs using Maven

I learned Spring via Spring In Action 3 few month ago. I downloaded Spring libraries from official site (list was like in SIA3(aop, asm, aspects, beans ...)), added them to my project and everything worked fine. Now I want to use Maven, but I am getting a lot of errors and sinking in searching what library to add.
I am newby, dont know all Spring dependencies(within it libs) and the question is not about my errors, but about the way to add all Spring libraries to my project via Maven. How do you usually add Spring libs using Maven?
You don't have to download the libraries themselves anymore. That is what Maven is for. (and quite some more, of course)
set up Maven properly
set up Maven in the IDE tool you have (like this)
edit the pom.xml to include what you need, adding the dependencies in the in the dependencies tag.
Maven takes care of resolving the dependencies of the specified packages. If a package depends on other packages, it will do it for you. You only have to specify the packages you directly need
For example
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6</version>
</dependency>
You can easily find the packages using Google, and searching for "maven repository "
Avoiding version clashes
Also, as Bart mentioned, the common way of having Spring in the pom.xml - as it has way too many versions, and clashes can occur - is through a common property specifying the version for all Spring components. (Based on this answer)
Specify the property in the properties tag:
<properties>
<spring.version>3.0.5.RELEASE</spring.version>
</properties>
Then use it in the dependencies like this:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
Be careful to use it for ALL components to avoid version clashes. (of course, issues mught still occur, bz having different libraries reference spring too, but that is another story in its own.)
Side note
Keep in mind note that Maven projects use specific directory layout. When I first started using maven for my own projects, first I created a new blank one, and played around with it, before I began migrating my older projects to use maven. Believe me, it pays off.
Add spring artifacts to your pom.xml file. For example
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.2.4.RELEASE</version>
You can find more artifact info here
http://mvnrepository.com/
HERE you can find the dependencies as per your requirement. Just click on the dependency and inside click on the latest release, scroll down there is your code inside the <dependencies> Your required dependency and version</dependencies>.
Just copy the XML code and paste it in your pom.xml file.

Categories