Using SQLcl in maven java project - java

I'm trying to use SQLcl in my maven Java project, but I cannot figure out how to use it.
What I have tried so far:
I downloaded the latest SQLcl (sqlcl-19.4.0.354.0937.zip) from oracle.
I extracted all the files into a local folder. I then opened the sqlcl-19.4.0.354.0937\sqlcl\lib folder with terminal and ran 'mvn validate'. Maven stated that 'ucp.jar' is missing. I downloaded that jar from oracle downloads and ran it again. This time it 'seemed to run successfully'. I also tried to 'mvn clean install' with same results.
However, I'm unable to find 'dbtools-common.jar', 'dbtools-http.jar' or 'dbtools-sqlcl.jar' files anywhere in my m2 folder. This tutorial was explaining to do it like this. Intellij is unable to import classes like 'ScriptParser' because the dependencies are missing.
What's the correct way to do this?

The pom sqlcl/lib is used for installing dependent jars into your local repository. However, its not for installing the sqlcl jars (dbtools-*) into your local repository.
You can certainly tweak it to do so, and use them as #Hooman.AS suggests.
The pom is to load the dependencies for the jdbcrest so that users can try out the rest jdbc driver.

Related

Generate sources from a local jar file in Maven

I have a locally stored jar file that I believe I need to generate the sources in order to consume it in my project.
I am using JDK 8, IntelliJ and Maven 3.5.2
I have installed the jar file into my local .m2 folder.
Perhaps I am missing a goal in my maven lifecycle or a plugin?
Not had to use a local jar dependency before so any help appreciated (I'm a tester not a developer)
I've attached a screenshot (apologies for all the obfuscation of package names that I feel might be commercially sensitive - possibly overkill!)
Note the red underlining in the src test....folders where the classes cannot access those within the jar dependency.
I have added the dependency within the pom.xml file also and it shows no errors.
I feel I should have run something like -Dsources=target/mycool-project-3.0.17-SNAPSHOT-sources.jar when using the mvn install:install-file command (which I used originally when installing to my .m2. However I tried this with no success.
Or maybe I need to mark the resources as a root within IntelliJ
Currently in Project Structure -> Libraries I see:

Maven is not putting generated jars into the local repository

I recently did a pull on the local repository. I ran into some missing dependencies, nothing unusual there. I ran mvn clean -U install on the projects concerned, no problem, everything looks good in maven on the command line. I refresh my projects in eclipse, no joy, eclipse says I'm missing dependencies.
After a bit of messing around back and forth with no success, I looked in the local repository itself. Sure enough, many of the required dependencies are missing; they are however, located in the target folder.
I've tried building with install a number of times, but the jars aren't placed in the local repository, so my other projects can't find them.
Sometimes a later version of the library is there, but not an earlier on, for example 6.0.28-SNAPSHOT is there but not 6.0.27-SNAPSHOT.
I have checked my settings in eclipse and maven:
Eclipse is using the correct version of maven
They both have the same local repository
They are both using the same settings.xml file
They are both using the same version of Java
Since all the jars I checked appear to be in the target folder, I think the issue is with maven not installing them into the local repository. What could cause this issue, and how can i resolve it?
Also, although I don't think this is relevant myself, as everything has been working fine before, my target directory is a completely separate folder, and is not a sub-folder of each project. It's located in C:\Maven\target.
I forgot to run:
mvn eclipse:eclipse
After pulling the updates from git.

How to find and missing artifacts in a maven project using eclipse as editor?

I am working on a Maven project and I am using eclipse as an editor. I clone a project from GIT and then create a git repository in eclipse , import it and then create a maven project. After i finished the project of setup i got a lot of errors and this is due to pom.xml file and I am missing about 300 artifacts.I know want to know how can i find and add those artifacts in my project. I have seen different answers for that and one of the answers is to upload maven project. I did it but still not working , I am still missing the artifacts.
I really need some help here since i want to start working on this project as soon as possible.
Maven pulls all the dependencies either from maven repository or from local repository automatically (typically C:/Users/user1/.m2 on windows). if there are lot of dependencies, eclipse takes a while to download them all.
check if you see building workspace at the right bottom corner of eclipse. you can press Alt+F5 to refresh the project and then try command mvn clean install from your root folder (where your pom.xml is placed)
Sometimes, jars are not available on maven repository such as sqljdbc. in that case you will have to manually install them to your local repo using below command if you have the .jar file
mvn install:install-file -Dfile=<path-to-file>/stax-1.0.jar
-DgroupId=stax -DartifactId=stax -Dversion=1.0 -Dpackaging=jar
or a quick and dirty approach would be copy the .m2/repository folder from previous machine if project was working good on that machine.

How to download all possible maven dependencies so they are local

I work behind a very massive firewall that likes to hiccup on random connections, which makes all work with remote repositories a living nightmare for me!
I am looking to work with a project from Git (this one https://github.com/mrniko/netty-socketio) which heavily utilizes maven for downloading dependencies.
What I would like to do is on another terminal (such as http://cloud9.io or something) download all the maven dependencies so that the entire project can be run standalone.
I have already tried mvn clean install and then zipping up the source folder, but its actually not enough! I still get ClassNotFound related errors when I try to run the project locally in eclipse. And for the record, I did add the compiled *.class files in the build properties, so Eclipse knows where they are. It seems like there are some random classes that get generated dynamically which still aren't present (such as log4j -- and I really don't want to hunt each one down individually)
I am wondering if there is a fully thorough way to download all possible dependencies from maven and then either run a project 100% standalone, or create a local maven server from it?
I am running Java 7 on Eclipse Luna and I do have Maven installed on my windows 7 machine (though again it barely works on remote repositories). I also have a Cloud9 instance which I could use to run Maven commands, then zip up the results for local download.
When you execute mvn clean install, maven downloads all dependencies of currently built project to your local maven repository. This is usually located in
%USERPROFILE%\.m2\repository
When you build your project, maven uses that path, to lookup required dependencies.
If you want do download them all, you can try using mvn dependency:copy-dependencies. Then, you'll find all project dependencies intarget/dependencies directory of your project. This also includes transitive dependencies.
To add them all as eclipse dependencies, you may want to try maven-eclipse-plugin. Using that plugin, you can generate eclipse .project and .classpath files, using mvn eclipse:eclipse command. This will populate eclipse files with required dependencies from maven. You should then import the project to eclipse using Import existing projects into workspace, instead of Import existing maven projects.
maven-eclipse-plugin will add all those jars relative to a folder specified by M2_REPO variable. Just make sure you edit this variable inside eclipse project properties, and you should be set.
I've had to deal with similar issues. I would find that due to changes in firewall policies, occasionally all the .jar files in my project had been updated to be a 1K file that, when opened within notepad++ contained a message from the firewall saying that the download had been blocked.
I recommend looking into Nexus for your local repository management, it means your local projects don't have to go past your firewalls to check for maven updates.
http://www.andrejkoelewijn.com/blog/2010/03/09/getting-started-with-nexus-maven-repository-manager/
Use dependency plugin go-offline task.

Import and use a Maven managed Java library (CitySDK)

I am trying to build a web application based on the project library CitySDK, but i don't know how to import it properly into my own project.
I have created a Maven Web Application and added the CitySDK library as a Dependency, and then Selected the Project, right-clicked and Selected Build with Dependencies. No errors appeared, and in the image below you can see it appeared as a dependency.
However, whenever i try to use some of the classes specific to it, in my own Web Application(called TourismApplication's TestClass.java), the compiler displays an error, that the package is unknown. Could anyone suggest ideas as to what i have missed? I have followed a few Maven tutorials, but without any effects.
The dependencies are as follows:
Ok I did some digging and I think I figured out your problem. Their POM file is incorrect based on the structure of project.
First off, I'll paraphrase what I think the steps you took to get it built in your project were, to ensure I followed the same steps to get it working. These are the steps I took:
Cloned/downloaded the sources from the link you placed in the OP
Built the project into a jar file by running the command they said to use: mvn clean package assembly:single
Installed the artifact in your local Maven repo using mvn install
Added a dependency in your project POM
I tried the same thing you did, using the library in a test source file, to no avail. I looked at the .jar file that was built using their instructions and didn't find any .class files archived into it... it was essentially empty.
Turns out, their src folder structure follows Maven standards, but their POM file indicates the sources are down a different chain of directories. If you examine the build log closely, you see "[INFO] No sources to compile"
The POM.xml file they provide specifies the source directory as
<sourceDirectory>src/citysdk/tourism/client</sourceDirectory>
However, the actual files are at
src\main\java\citysdk\tourism\client
After changing the line in the POM file from the above to (similarly for tests):
<sourceDirectory>src/main/java/citysdk/tourism/client</sourceDirectory>
<testSourceDirectory>src/test/java/citysdk/tourism/client/tests</testSourceDirectory>
rebuilt, and installed, it worked when I tried to use it in my project. Hope this helps.
FYI, I used IntelliJ as my IDE, but it should work the same with Eclipse.

Categories