How to download an Excel file from the web using Maven? - java

I'm trying to download a .xlsx file using the following plugin, in my project's pom.xml file:
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
<execution>
<id>getExcelFile</id>
<phase>generate-sources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>http://example-url.xlsx</url>
<outputFileName>file.xlsx</outputFileName>
<outputDirectory>${Dir}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
However, the file becomes corrupted once downloaded and is empty. It isn't a problem with the file, as whenever I download it from the web and open it manually, it is fine.
Can someone help me out please?

Related

why do I not find generated source files for grpc and protobuf when using maven and java in vscode

I have a pom file that correctly generates the grpc and protobuf source files I need in target/generated-sources when run from the command line. But when I build in vscode those directories are empty and references to the protobufs are undefined. Here's the section of my pom file that builds the grpc source.
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.0</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.2.0:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
I added the following based on what I read in other posts to prevent vscode/eclipse from removing the generated source directories
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/protobuf/grpc-java</source>
<source>/target/generated-sources/protobuf/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
When vs-code builds, the target generated-source directories are there, but there is no source in them. We had a similar problem with intellij but were able to work around it by running the maven command line build before opening intellij but that does not seem to work for vscode.
Use protoc-jar-maven-plugin instead.
Sample usage please view protoc-jar-maven-plugin.

Build angular 11 with Spring boot 2.x in one single jar

I am facing an issue bulding an angular 11 with Springboot jar.
If I runn separatelly the apps (the backend on 8080 and the ui on 4200) they work just fine, the connection and calls in between are ok and stable.
What I am trying to do is actually integrate this. I've seen plenty of examples but I don't know where and what Am I doing wrong.
Here is a picture of the Project structure:
Here are the maven plugins which are installing and copying the ui build stuff into the jar.
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>${frontend-maven-plugin.version}</version>
<configuration>
<nodeVersion>${node.version}</nodeVersion>
<workingDirectory>${frontendSrcDir}</workingDirectory>
<installDirectory>${project.build.directory}</installDirectory>
<environmentVariables>
<CI>true</CI>
</environmentVariables>
<!--suppress UnresolvedMavenProperty -->
<skip>${skip.ui}</skip>
</configuration>
<executions>
<execution>
<id>install-frontend-tools</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v14.16.0</nodeVersion>
<npmVersion>6.14.13</npmVersion>
</configuration>
</execution>
<execution>
<id>npm-install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>build-frontend</id>
<goals>
<goal>npm</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<arguments>run build --prod</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>angular-build</id>
<goals>
<goal>copy-resources</goal>
</goals>
<phase>validate</phase>
<configuration>
<outputDirectory>${project.build.outputDirectory}/static</outputDirectory>
<resources>
<resource>
<directory>${frontendSrcDir}/dist/ui</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
In the jar the build files are copied under jar/BOOT-INF/classes/static.
Here is the image
What Am I missing?
Spring boot automatically serves static content if you have a folder in "resources" called "static" or "public". So put all of the compiled files from angular in a folder called "static" under resources.
Doing so will make spring boot serve angular :)
In #Aborgh answer,
So put all of the compiled files from angular in a folder called "static" under resources.
That is correct, and I am just adding some more. Specifically, when you run the build command such as npm build, it generates static files such as xxx.html, xxx.js, xxx.css in the dist folder.
So you want to copy all the files under dist and paste them into your Springboot project, place them right into the resources/static folder.
Not relevant to your question, but I would recommend you put the static files somewhere separated from your Springboot backend application. Try reverse proxies such as Nginx so you can resolve requests such as https://example.com/api/xxx to your Springboot backend application and all other requests such as https://example.com/foo/xxx to your frontend Angular views.

Add generated Apache Avro source with build-helper-maven-plugin

I'm using Apache avro to generate some pojos, all work very well in run, expect that the generated source is marked as inexistent in imports on IDE (intellij) .
I tried to use build-helper-maven-plugin to add source, but it doesn't work
this is my maven configuration for apache avro and build helper plugins :
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>${avro.version}</version>
<configuration>
<stringType>String</stringType>
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
<configuration>
<sourceDirectory>${project.basedir}/src/main/avro/</sourceDirectory>
<outputDirectory>${project.build.directory}/generated-sources/</outputDirectory>
<imports>
<import>${project.basedir}/src/main/avro/errorkind.avsc</import>
</imports>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
Try changing your pom with following and run clean install and then you should be able to import.
<configuration>
<sourceDirectory>${project.basedir}/src/main/resources/</sourceDirectory>
<source>${project.build.directory}/generated-sources</source>
</configuration>
In POM InteliJ may give you a fake error after adding this but your build will success.
"generated-sources" reside under ${project.build.directory}/target folder
Also, try marking "generated-sources" as source directory. You can do that by:
Project Structure → Modules → Click the generated-sources folder and make it a sources folder.

Download an xlsx file in pom.xml

I am trying to download a .xlsx file into my project's resources using the following execution:
<execution>
<id>${id}</id>
<phase>generate-sources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>${url}</url>
<outputFileName>${fileOutput}</outputFileName>
<outputDirectory>${licensesDir}/em</outputDirectory>
</configuration>
</execution>
However, the file that it generates is empty and cannot be read. I know it's not a problem with the file I'm trying to download because whenever I download it directly and copy it into my project manually, I can read it it fine, and it works with my code. It also downloads other file types just fine.
Yet, whenever I try to do download it this way, in the pom.xml, the generated file is empty and my code generates a NullPointerException exception when run.
Could anyone provide some help please?
What you need is Maven Download Plugin: https://github.com/maven-download-plugin/maven-download-plugin
Add plugin to your pom and execute goal like this:
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
<execution>
<id>install-jbpm</id>
<phase>pre-integration-test</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>http://downloads.sourceforge.net/project/jbpm/jBPM%203/jbpm-3.1.4/jbpm-3.1.4.zip</url>
<unpack>true</unpack>
<outputDirectory>${project.build.directory}/jbpm-3.1.4</outputDirectory>
<md5>df65b5642f33676313ebe4d5b69a3fff</md5>
</configuration>
</execution>
</executions>
</plugin>

Maven wsdl import. How to use the generated files?

i have a problem and I'm not able to solve or understand the hole workflow behind this process.
I use eclipse with maven.
This is my simple test pom.xml
...
<dependencies>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.8</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<xdebug>true</xdebug>
<verbose>true</verbose>
<keep>true</keep>
<packageName>abc.model</packageName>
<sourceDestDir>${project.build.directory}/generated-sources/wsimport/</sourceDestDir>
</configuration>
</execution>
</executions>
</plugin>
<plugin> <groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/wsimport/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
The jaxws-maven-plugin generate the files in the sourceDestDir. The build-helper-maven-plugin add the files during the maven install process the to the correct folder and also into the resulting jar file. So far so good.
But I'm not able to use the generated files/classes in eclipse. So in eclipse maven does not recognize the files as source or does not but this in the source path. Did I make an mistake or did I miss something?
Thanks for your help.
Update:
I observer a strange behavior. Same test project same pom file. If I import this existing Maven Project in eclipse it works like expected. I can directly use the generated files as source.
But if I delete this source folder, I'm still not able to restore this with maven.

Categories