I'm creating a custom document library action in Alfresco Content Services 6.1.1 using alfresco-amp-archetype. I'd like to access data from external Oracle database.
I'm using ojdbc library from: https://mvnrepository.com/artifact/com.oracle.jdbc/ojdbc8/12.2.0.1
Since maven is unable to download the dependency on its own, I'm putting the jar in my project and adding it in pom (I've also added it in tomcat/lib directory):
<dependency>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ojdbc</artifactId>
<version>8</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/ojdbc8-12.2.0.1.jar</systemPath>
</dependency>
When I call the action I'm getting "java.sql.SQLException: No suitable driver found for jdbc:oracle:thin"
How should I add the driver to my project for it to work?
The system scope that you are using is more meant to include things provided by java itself and is a deprecated feature.
The jar is not in the usual maven repositories due to license restrictions. So it needs to be somewhere with private access.
If you are not running a maven repository proxy like sonatype nexus or jfrog artifactory I would recommend that you copy the jar into your own maven repository: maven deploy into local repository
(probably best in a little script to repeat or share).
Don't store it in src/main/resources - everything in there will be added into the artifact you create. Choose another folder (like "dependencies" beside src) and then once copied into your local maven repository use that jar as normal dependency (remove scope and systemPath). The default scope is compile, so the jar will be included in your classpath so the driver should then be available (I assume you create some sort of war file?).
So there is also no need to manually add it into tomcat directly - but have it brought in via the war file.
Related
I have local Maven repository in C:\Users\<User_Name>\.m2 directory. After getting "java.lang.NoSuchMethodError..." exception and navigating problem on the web, I see this page mentioning to remove unused jar version(s) from local repository.
My questions are:
1. When I look at C:\Users\<User_Name>\.m2\repository\org\mockito\mockito-core folder, there are 52 different version folder. I think it is similar for other jar libraries. So, should we clean unused jars periodically? Or should we keep unused versions of a jar library?
2. If I just have 3.0.0 version of mockito-core in my pom.xml, how the app use or mix another version(s) in the local repository? Normally, if I just a single mockito-core dependency in my pom.xml, may there be any problem as mentioned on that page (solving the problem after removing other jar version)?
1)
You do not need to "clean unused jars" from your local maven repo manually. How do you want to decide which jar, which version is unused? Maybe your next project will use the jar that you want to delete. Who knows.
If you have enough disk space then you can leave your local maven repo directory untouched for years. If this directory grows too big, then I suggest you delete the complete .m2 folder. Then the next time when you build a project, Maven will download automatically all dependencies that your project needs.
There is only one use-case when deleting your local maven repo can cause a headache: if you have installed some custom jars manually.
2)
It is highly possible that the different dependency versions that you see in your local Maven repo directory come from different projects that you built earlier.
Anyway, you can display your effective pon with the Apache Maven Help Plugin.
I got the "Archive for required library cannot be read or is not a valid ZIP file" error for my maven project I imported in Eclipse. I read some posts about this and suggested is to delete the faulty directory like in my case:
~.m2\repository\com\cogentex\rpw\2.2 and
~.m2\repository\com\cogentex\rpw-lkb\2.2
Then you should update the project via Eclipse: Maven>Update project and click force update of snapshots/releases.
I followed these steps and the directory looks like this now:
So the correct .jar files are still missing and it also results in more erorrs now:
1: Missing artifact com.cogentex:rpw-lkb:jar:2.2
2: Missing artifact com.cogentex:rpw:jar:2.2
3: The container 'Maven Dependencies' references non existing library '~.m2\repository\com\cogentex\rpw\2.2\rpw-2.2.jar'
Here is the snippet from the pom.xml which throws the first two errors:
<dependency>
<groupId>com.cogentex</groupId>
<artifactId>rpw</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>com.cogentex</groupId>
<artifactId>rpw-lkb</artifactId>
<version>2.2</version>
</dependency>
What do I have to do to make maven download the correct .jar files? I already tried running maven cleanor maven install and restarting Eclipse.
What you see in the folder is some files that indicate the artifact was not found and when was the last time Maven checked.
Whatever com.cogentex:rpw is, it's not in Maven Central so Maven will not find it there. You need to tell Maven where to get it from by providing the URL to a repository that contains it. If/when your POM has the repository, make sure
you do have access to the reposiory from the environment you run your build in (check proxies, firewalls, ...)
the GAV coordinates (groupId, artifactId, version) are correct and match the one in the repository.
the artifact type in the repository is jar. If it is not, provide the correct type in the dependency
the artifact is not deployed to the repository with classifier. If it is, provide the classifier in the dependency
This question already has answers here:
Add a dependency in Maven
(5 answers)
Closed 3 years ago.
My area of expertise is not Java. I develop in other languages on other platforms.
Right now I'm developing a series of Java servlets for a project. The servlets are to run on a CentOS server running FileNetP8.
I actually got all of the planned items finished and running.
Now when I am trying to add a few more services, the library I came across is available via Maven. I have no idea what Maven is. Read up on it today. Created a test project to try it out.
My development environment is Eclipse Photon on Windows 10.
Now my problem is I can't figure out how to add the Filenet JARs to the project. I can't upload them to some Maven repo. Searching the Web says to add them to the local repo, but I don't understand how to do that to the Local repo in Eclipse's builtin Maven.
I think that the JARs don't need to be packaged within the deployment WAR because the app will be deployed to the Websphere server that runs Filenet so they should be available on it. Should I add them as external JAR references to get the project to compile?
I provide below the following approaches to check based upon your suitability.
Approach-1: Install manually
If you have only 1 jar file, execute the following command by replacing as per your requirements.
mvn install:install-file \
-Dfile=<file path location> \
-DgroupId=<your own custom group id> \
-DartifactId=<your own custom artifact id> \
-Dversion=<some version number> \
-Dpackaging=jar \
-DgeneratePom=true
Once it is done, use the following in your project pom.xml in the dependency section.
<dependency>
<groupId>your own custom group id</groupId>
<artifactId>your own custom artifact id</artifactId>
<version>some version number</version>
</dependency>
The downside of the above approach is, only you can use it as it installs in your .m2 directory. For other developers, they have to follow the same approach. It is not a suggested approach.
Approach-2: Manually add the location of jar file
Add the following dependency in pom.xml
<dependency>
<groupId>some.group.id</groupId>
<artifactId>some.artifat.id</artifactId>
<version>some.version.no</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/yourActualJarFileName.jar</systemPath>
</dependency>
The downside of the above approach is, you have to put all the jar files in a directory and you have to provide the path. All the jar files should be part of your project, it means all the jar file should be put in source code repository. Although it servers the purposes, still it is not a good approach. If you got a newer/higher version of jar file, again you have to put it inside your lib directory. It means you have manage all the old and new versions of jar files.
Best Approach
Maintain Nexus or Artifactory, or any artifactory management system in the organisation and put all the jar files and provide the definition of your custom jar file. It will provide you pom definition. Based upon this, you have to add the dependencies in your project pom.xml. Here you can maintain n number version of your custom jar files.
Seeing as every answer involves maven i'll try to provide a different and somewhat old school approach. You could always import your jars directly into your project by right clicking on it -> properties -> Add Jars. Apply when done and VoilĂ . This is far easier than understanding the complexity of maven.
Dependencies need to be added in pom.xml under dependencies tag. Maven will download the specified jars from maven central repository for the first time, and it will be saved in your local repo.
If the dependencies are not available in central repo and if they have their own repo, you to need specify it in the repositories tag.
<repositories>
<repository>
<id>repo-id</id>
<name>repo-name</name>
<url>http://repourl</url>
</repository>
</repositories>
Any change in the pom.xml, maven will automatically download it.
<dependencies>
<dependency>
<groupId>dependency-id</groupId>
<artifactId>artifactid</artifactId>
<version>1</version>
</dependency>
</dependencies>
If the jars are available in Maven Central repo then all you hvae to do is add dependency under dependencies section in your pom.xml file. Set the scope as required, like you said jars don't needed to be packaged in WAR file as they might be available on server then you can set scope to provided.
<dependency>
<groupId>groud-id</groupId>
<artifactId>artifact-id</artifactId>
<version>version-numbe</version>
<scope>scope</scope>
</dependency>
If jars are not available in central repo and you want to install them on your local repo then below command should help you. More information here.
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
Within my deployment procedure I need to deploy specific jar to TOMCAT/lib folder instead of default deploy location WEB-INF/lib. Is there a way to specify this to Maven pom.xml so that I don't need to think of this jar alone?
Specific project is extension for Alfresco which is built based on Alfresco's Alfresco Maven plugin. However this looks to me as requirement that any Java developer should want regardless of used technology. Am I missing the obvious?
I think I understand what you're asking about, let me know if I'm misunderstanding.
Alfresco's Maven Plugin for the SDK Version 3.0.1 (That's what I'm currently using, at least) has a configuration tag called tomcatDependencies which is mentioned in their documentation here.
That being said, it doesn't really explain how to use it.
Here's a snippet that would show configuring a dependency for the Tomcat plugin it uses.
<groupId>org.alfresco.maven.plugin</groupId>
<artifactId>alfresco-maven-plugin</artifactId>
<version>${alfresco.sdk.version}</version>
<configuration>
<tomcatDependencies>
<tomcatDependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0</version>
</tomcatDependency>
</tomcatDependencies>
<!-- disabling the flat file H2 database to run the Repo -->
<enableH2>false</enableH2>
<!-- using the enterprise DB global properties where we configure oracle DB -->
<enableEnterpriseDb>true</enableEnterpriseDb>
You can install the jar in your local maven repo and then reference it as a tomcat dependency there.
Here's a link to some directions on how to install that jar to your local maven repo.
Hope this is what you were looking for.
simple scenario:
I have a maven project, containing some maven dependencies (activiti framework) and added the Widlfly 8.1.0 runtime as library in eclipse.
naturally now, if i clean and build with MAVEN, maven won't consider the runtime while compiling and complain that it cannot find eg. the #Webservlet Annotation, HttpRequest classes etc.
so in order to build my Project, i have to run any maven goal and see it fail, just to have maven download all dependencies, then build the project with eclipses' build process which then uses all downloaded maven dependencies AND the wildfly 8.1.0 runtime, succeeding in building the project.
THEN only can I run maven install/deploy to create the .war, which works, because maven finds a compiled target folder, created by eclipse.
How can i, without instlalling all runtime jars to my local repository or adding the wildfly installation as antoher local repo, tell maven or the m2e plugin to include manually added libraries to mavens compile step?
what you probably want is a "provided"*-scope dependency on org.wildfly:wildfly-spec-api:8.1.0 (which is a pom artifact containing all the apis/specifications provided to you by wildfly).
assumming you intend to deploy your app inside wildfly (as opposed to embedding wildfly in your own main() somehow...) you dont need a dependency on the wildfly container.
* - note that since wildfly-apec-api is a pom artifact (and not a jar) you need to use the import scope and not provided. see this article for a complete guide. the gist is you put an import scope dependency on the pom in dependency management, and then you can put a provided-scope dependency on any specific member api/spec that you use (say ejb3, jsf, bean validation or jpa) and the versions will be taken from the spec-api pom.