Apache Buildr - extract artifact to project root - java

I started using Apache builder for a project and I am surprised how little code I need to build my project. But after the first successes, a problem arose:
I have some required text files stored in a jar file which can be downloaded from a repository. I have included it in my buildfile as an artifact and can download an compile with it.
Now I want to extract the contents of the jar and place it in the root folder of my project. Is there a way that Apache Buildr can do this for me? Just adding it to the classpath is not sufficient.

I believe this is the example you are looking for, from http://buildr.apache.org/artifacts.html
bean_jar = file('target/app/bean.jar'=>unzip('target/app'=>app_zip))
You can also directly call Buildr's Unzip, just don't forget the extract at the end.
Unzip.new( 'path/to/extra/to' => 'file/to/unzip').extract

A jar file is a zip file. You can use buildr's built-in unzip helper to unzip it wherever you'd like. The unzip helper is documented in the artifacts section of the buildr docs.
If you need to get the filename of an artifact that buildr has downloaded, you can call #to_s on the artifact:
artifact('net.example:text-files:jar:1.0.0').to_s

Related

java zip END header not found

I am currently developing a minecraft plugin that depends on other plugins to function. Shading the other plugins into my own plugin isn't an option since it is impossible to load three different plugins from within the same jar. That's why I need to do it like this. (Another option would be to just use some kind of maven API to download my library on runtime but I have no idea how to google for that)
There is a jar file in the resources of my plugin and I copy it to the outside using Files.copy(this.class.getResourceAsStream("myjar.jar"), new File("myjar.jar").toPath()) but when I try to load it, there's an exception thrown: java.util.zip.ZipException: zip END header not found. The jar in my resources directory is fine. I'm able to unzip it. When I try to unzip the file created by my program my ark (Linux zip viewer) complains about the zip file being broken. How can I copy the file without the file breaking?
If you have any idea how I can shade a maven wrapper or something in my jar to download the other plugin from a maven repository that would be nice too. I also somewhat tried to look up how maven repositories are built to kind of reverse engineer the maven dependency function but I gave up because I don't want to write my own sucky version of maven.
Thank you for reading my question.

How to setup gg.classpath for Oracle goldengate BigQuery Adapter

Im tryinig to configure the BigQuery adapter for Oracle golden gate (12c). But unfortunately Im not able to understand this gg.classpath. In the doc, they mentioned to download client Lib from the GitHub
But it contains so many folders, I don't know what folder I can download and where to copy them.
Also we have download some JAR files, and put it a directory.
Next, download the following JARs from Maven Central, and then include them in the classpath for the BigQuery Handler:
Where I can put these JAR files?
Can someone give me an example to configure the gg.classpath
Oracle doc link: https://docs.oracle.com/en/middleware/goldengate/big-data/12.3.2.1/gadbd/using-bigquery-handler.html#GUID-A8426075-81E8-47AB-BA15-3C564751A490
example gg.classpath: gg.classpath= /path_to_repository/bigquery/libs/*:/path_to_repository/bigquery/*
You can download the jars file from maven as mentioned in the documentation. Once you have download the jar files you can place them in any directory of the server/machine where you have installed Oracle GoldenGate for BigData. Lets say for example /u01/OGG. After that you can include that directory in the classpath as below.
Example:
gg.classpath=dirprm:/u01/OGG/jdk1.8.0_221/:/u01/OGG/oci-java-sdk/lib/:/u01/OGG/oci-java-sdk/third-party/lib/:/u01/OGG/hdfs_jar/:/u01/OGG/parquet_jar/*
In the above example i have downloaded OCI Handler, Parquet Handler and their dependency and placed them in path /u01/OGG/. Here handler_name is oci-java-sdk and parquet_jar.
Just leaving the answer here, so others can benefit from this.
-- Steps for manually build the jar files
-- Or download all the jar from the above link and skip all these steps.
apt install maven
git clone https://github.com/googleapis/google-api-java-client-services.git
cd google-api-java-client-services/clients/google-api-services-bigquery/v2/1.29.2/
mvn clean install
-- Copy all the jar files to /opt/ogg/jar
mkdir -p /opt/ogg/jar
cp target/*.jar /opt/ogg/jar
-- We also need to download the following JARs from Maven Central
-- download path /opt/ogg/jar
api-common-1.6.0.jar
gax-1.28.0.jar
gax-httpjson-0.45.0.jar
google-auth-library-credentials-0.9.1.jar
google-auth-library-oauth2-http-0.9.1.jar
google-cloud-bigquery-1.31.0.jar
google-cloud-core-1.35.0.jar
google-cloud-core-http-1.35.0.jar
google-http-client-jackson-1.23.0.jar
guava-25.1-jre.jar
threetenbp-1.3.6.jar
Or I have a zip file that contains all the necessary files. You can get it from the below link.
https://github.com/BhuviTheDataGuy/medium-blog-files/raw/master/golden-gate-bigquery/jar-files.zip
For more detailed Step by step Setup for Oracle to BigQuery, refer the below link.
https://medium.com/searce/sync-oracle-to-bigquery-with-golden-gate-bigquery-adapter-59991bbdb5e3

How to access file in a JAR when running a Maven build

I want to run a liquibase update by the liquibase-maven-plugin, but the changeset yml file is inside a .jar that I pull in by dependency.
When I open the .jar with TotalCommander, it has the following structure:
xy.jar/changelog/changeset.yml.
I tried including it as a resource directory, but it failed telling me the .jar is not a directory.
I also tried building to a WAR and just setting the liquibase changeLogFile property to the path leading to the .jar, like {projectDir}/target/..war/..lib/..jar/changelog/myFile.yml
But maven could not find it this way.
Is it possible to access this file somehow?
You can read the file using below code.
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("changelog/myFile.yml");
Thanks for the reply, but the solution was simpler, I'm just rusty in this area :) I simply had to add the required JAR from the WAR as a Maven Dependency. This adds the JAR's content to the classpath in the Maven build process, so I can reference to it's files as they were on the project root path.
TLDR: add JAR as dependency in the pom and use the path:
<changeLogFile>changelog/xy.jar</changeLogFile>

Add library into jar of project

My problem is with a project where I use the POI library. It's from apache and allows you to work with excel,word, ... .
I had to add some jar files to my library and it runs perfect.
The problem is when I put my JAR file somewhere else.
It gives me the errors it can't find the librarys.
Is there a way I can put my librarys into the 1 jar?
I already tried to add my lib folder as source package but that didn't help.
there is a Maven plugin for Eclipse called M2Eclipse, which will read a POM and construct a classpath out of jars it finds in the local repository and any remote repositories you've configured. It behaves largely like Maven does in terms of finding the latest version for a given jar (if you've specified a version range in your POM).
You can also have a look on this
http://fredpuls.com/site/softwaredevelopment/java/deploy/five_strategies_for_managing_j.htm
You want to make a 'shaded' or 'uber' jar, which has all of its dependencies included
There is a maven plugin for building a shaded jar.
https://maven.apache.org/plugins/maven-shade-plugin/
For me the fastest/ easiest solution was to just open my project in eclips and export is a runable JAR then it adds the librarys to the JAR.
NetBeans builds your application into the project's dist folder. There is also a readme file in it, that tells you, you should distribute the contents of that folder...
Edit
Remove the lib folder, that is shown on the second image, from your sources.

How to build project from maven pom file

I have a maven pom file for an open source project. This pom file has all the info like what other jars it depends on etc. I installed maven. Created a dir samprj and copied the pom file into that dir. Cd into that dir and ran mvn command without any arguments but I got bunch of errors. I am absolutely new to maven so I think I am missing something. I tried also from Eclipse ( Import project -- exisitng maven project) but that also does not work except eclipse creates a project that has just that file pom.xml. I expect something that first it will download the jar for the project and then download all dependent jars and config files but nothing there.
So given a pom file how do I build the project from it?
mvn install should get you going
I have a maven pom file for an open source project. This pom file has all the info like what other jars it depends on etc. I installed maven. Created a dir samprj and copied the pom file into that dir ...
It sounds like you only have the project's POM file. This is not sufficient. You need to checkout the complete source tree for the project. Having done that, change directory to the directory containing the POM file and run mvn install.
Also, don't copy the POM to a different directory. Maven expects to find all of the source files relative to the POM file location.
FOLLOW UP
Thanks for advice. I was not able to use the command mvn install as it gave errors.
Probably because you hadn't checked out the source.
I don't know how to check the source tree of the project ...
Use a subversion client (the svn command for example), or one of the Eclipse subversion plugins.
If this was a properly documented project, there would be clear instructions on what version control and build tools you needed, how to checkout the source code and how to build it.
... as I thought POM itself should have this information to automatically checkout if the source is not check out.
It doesn't necessarily, though in this particular case it does.
Anyway I was able use Eclipse to build the project without errors.
(Other readers can read #icyrock.com's answer for links to the m2eclipse plugin and documentation.)
The only problem is the dependent jars were downloaded but hidden deep paths in .m2 repository folder on my linux box.
But I would like these dependent jars to be relative to dir where POM file is.
Sorry, but that is not the way Maven works.
The ~/.m2/repository directory is a fundamental part of Maven. It is not a problem. It is a feature. (Don't fight it!)
If you want to open this within Eclipse, you need to install m2eclipse:
http://www.eclipse.org/m2e/
and then import the project as a Maven project as described here:
http://books.sonatype.com/m2eclipse-book/reference/creating-sect-importing-projects.html
Try out their getting started guide. It has a lot of good examples:
http://maven.apache.org/guides/getting-started/

Categories

Resources