I'm trying to package a Spring Project with Maven, but the Beans.xml file is missing.
A lot of people suggest to put the Bean.xml file in the main/resources, but it does not work for me. I think that only works for Eclipse user and I'm just compiling in the terminal using 'mvn clean install'.
Stupid mistake, inside my pom file the directory was like the following:
<build>
<resources>
<resource>
<directory>src/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<excludes>
<exclude>**/*.jpeg</exclude>
<exclude>**/*.gif</exclude>
</excludes>
</resource>
My resources folder was not inside src/main/resources, but src/resources.
And when I open my jar file the Beans.xml file this there and the code runs without error.
Related
I'm trying to create a Spring project structure where I have my HTML templates stored in the same src/main/java package (in Tapestry-like way), so the structure basically looks like this:
src/main/java
-org
-example
-views
-pageOne
PageOneController.java
Template.html
-pageTwo
PageTwoController.java
Template.html
However after packaging a WAR while using Maven I get a structure like this:
WEB-INF/classes
-org
-example
-views
-pageOne
PageOneController.class
-pageTwo
PageTwoController.class
So the .html files are ignored and obviously nothing works.
I tried to configure maven-resources-plugin to copy those resources like this:
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<filtering>false</filtering>
<includes>
<include>*/**.html</include>
</includes>
<excludes>
<exclude>*/**.java</exclude>
</excludes>
</resource>
</resources>
</build>
but to no avail.
How do I configure my project to copy non-java files from src/main/java into the final output?
It turns out that the problem was with maven modules. I have declared resources plugin in the main pom.xml instead of the module's pom.xml which lead to the configuration issues.
I'm using maven-resources-plugin to copy a file from resources dir to output dir and inject a variable;
there is the pom of the project:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
<configuration>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</plugin>
the resource file is something like this:
operation=${var}
and in he pom there is:
<properties>
<operation>true</operation>
</properties>
When I build the project (mvn -U clean package ) locally everything works fine: the file .properties is correctly inside the jar and it contains "operation=true".
The problem appears when I deploy the jar to my artifactory. If I download and open the jar from artifactory I can still find the .properties file, but in this case it contains: "operation=${var}" (the plugin doesn't inject the value of the variable). The command for the build inside the .yml file is the same that I run locally (mvn -U clena package). Any suggestions? The only difference that I can see is that on my computer I have maven 3.6.1 and on the server where I build the project for artifactory there is maven 3.3.3.
I have a maven Java project projA that build into a jar.
I have another maven Web project projB that holds a dependency of projA.
In proj A one of my classes accesses the resources located in the packages in projA.
When I expand the jar shown under dependencies in projB, I see that it does not contain the resource files (.dat).
What setting I need to do to copy these files into the jar when I build my projA in Netbeans
I am using NetBeans IDE 8.0.2 / Java 1.8
In your pom.xml, include something along the line like this:
<build>
<resources>
<resource>
<filtering>false</filtering>
<directory>src/main/java</directory>
<includes>
<include>**/*.dat</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
[...]
I have Java project made with maven. So I have typical maven project layout. And I use Jython. So I got few python files. Wich I use through PythonInterpreter in Java classes.
I place my python files in src/main/py folder. And I use this path to import the modules by interpreter. It works fine on my laptop.
The problem is:
When I do mvn install, this folder does not goes to the war.
I read about maven resources plugin and added this folder as a resource. Like this:
<resources>
<resource>
<directory>src/main/py</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
I that case it adds everything that folder contents, to web-inf/ directly, but not in the src/main/py. So that path is invalid for application in war archive.
Question is:
How should I place this python resource and what I should write in pom.xml, to be able to use the same path on the laptop, and the server?
Can you try including targetPath in the resource element as below:
<resource>
<targetPath>../</targetPath>
<directory>src/main/py</directory>
<includes>
<include>**/*.py</include>
</includes>
</resource>
I would suggest to use the src/main/scripts folder and check if they where packaged into the war if this does not work check the documentation of the maven-war-plugin and define it with the war plugin as described in the documentation.
<resources>
<resource>
<directory>src/main/py</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
is actually enough to include into jar/war file.
For running see
Compile Python Sources in Maven
It is not recommended to use src/main/py in your python script,
think as src/main/py as working/current folder for you python
while building a war file i am copying a set of jars from a location to a folder inside the war. While the files do get copied , however i think they get corrupted because the same class files of the jar when taken outside the war opens with a debugger while it does not open after taking from war file .
This is a part of my war pom.xml where i copy the jars
<execution>
<id>copy-jars</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/${project.artifactId}-${buildNumber}/somefolder</outputDirectory>
<resources>
<resource>
<directory>SomeSourceDirectory</directory>
<filtering>true</filtering>
<includes>
<include>**/**</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
SomeSourceDirectory has some jars and some other files
The result is:
myWar/somefolder/a.jar but when i open the classes inside this jar in a debugger..i get error in WinZip that
Invalid compressed data to extract.
Severe Error: Compressed data is invalid
However the same class file can be viewed when i view it in original folder i.e outside the war.
So is there a mistake while copying the jars?
Thanks.
Remove <filtering>true</filtering>, it corrupts the jar files.
Also, you can continue benefit to use maven filtering without corrupting jars inside.
We choose to exclude jar from filtered extensions.
In th pluginManagement section of the parent pom we put this configuration
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>jar</nonFilteredFileExtension>
<nonFilteredFileExtension>pdf</nonFilteredFileExtension>
<nonFilteredFileExtension>swf</nonFilteredFileExtension>
<nonFilteredFileExtension>zip</nonFilteredFileExtension>
<nonFilteredFileExtension>bz2</nonFilteredFileExtension>
<nonFilteredFileExtension>gz</nonFilteredFileExtension>
<nonFilteredFileExtension>acp</nonFilteredFileExtension>
<nonFilteredFileExtension>bin</nonFilteredFileExtension>
<nonFilteredFileExtension>odt</nonFilteredFileExtension>
<nonFilteredFileExtension>doc</nonFilteredFileExtension>
<nonFilteredFileExtension>xls</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
Note we added jar extensions as well as default maven excluded filetypes (its a zip after all).
Besides avoiding corruption of the archive it also speeds up the process as it does not have to filter large files.
Try Maven Assembly Plugin. It's my favourite plugin to add custom resources to a *.war file. See also Pre-defined Descriptor Files.
I had a similar error when I've added
<copy ...>
<fileset ... />
<filterchain>
<tokenfilter>
<replacestring from="..." to="..." />
</tokenfilter>
</filterchain>
</copy>
to my copy task in ANT. It corrupted the jar files when copying them.
I've solved this by applying the filter ONLY on the targeted text files and not on jar files.
Just as addition to the other answers, the other option is to enable the filtering only for the resources that require filtering:
<build>
...
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<includes>
<include>core.properties</include>
</includes>
</resource>
<resource>
<filtering>false</filtering>
<directory>src/main/resources</directory>
<includes>
<include>pdf/color_profile/sRGB.icc</include>
</includes>
</resource>
</resources>
</build>