Littered throughout my project are various property files located in packages that are not being included when the package goal is run from a Maven build.
Using the 0.10.2 m2eclipse plugin and the default "package" goal.
In the project:
src->main->java->mypackage->MyProperties.java
src->main->java->mypackage->MyProperties.properties
In expanded war directory after the "package" goal is run:
target->classes->mypackage->MyProperties.class
-- no property file --
I'm trying to get the group to adopt Maven and resolving this issue is going to be a deal maker. Moving the properties files isn't going to be practical. Any help is much appreciated.
Put your property files where Application/Library resources belong, i.e. in src/main/resources:
src/main/resources/mypackage/MyProperties.properties
And it will get copied properly.
Pascal's answer is the correct maven way of doing things.
But some developers like to keep resources next to their sources (it's standard procedure in wicket, for example).
If you're going to do that, you will have to add your source folder to the resources:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
</build>
Related
I am trying to import a maven project from a project created in IntelliJ IDEA.The problem is that the folder structure is messed up and is not as per as maven structure. Am I missing something here?
If you already have not same as Maven Standard Directory Layout, you can setting up custom paths to source folders into your pom.xml as code below or fix it manually based on standard maven structure.
Seems like into IntelliJ IDEA project you have lot of custom configuration into .idea files
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
In a maven web project (developed with Eclipse on JBoss), I have put the file displaytag.properties
paging.banner.placement=both
in the following three locations:
/myapp/src/main/java/displaytag.properties
/myapp/src/main/resources/displaytag.properties
/myapp/src/displaytag.properties
However, the file is not recognized. It does not affect the produced table.
Any ideas how I could understand what is wrong?
From DisplayTag Configuration properties:
For the whole web application, create a custom properties file named
displaytag.properties and place it in the application classpath
(tipically into WEB-INF/classes). Displaytag will use the locale of
the request object to determine the locale of the property file to
use; if the key required does not exist in the specified file, the key
will be loaded from a more general property file.
There is no WEB-INF/classes in my folder structure, since this folder was not created by Maven.
UPDATE:
I've found out the reason why my properties files were not copied from /myapp/src/main/resources/*.properties to WEB-INF/classes in the generated war file. I've had the following setting in my pom file:
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>applicationContext.xml</include>
<include>security-config.xml</include>
</includes>
</resource>
<resource>
<targetPath>WEB-INF/classes</targetPath>
<filtering>false</filtering>
<directory>../src/main/resources</directory>
<excludes>
<exclude>**/*.properties</exclude>
</excludes>
</resource>
</resources>
WEB-INF/classes is the location where the classes of a webapp are found at runtime, inside the generated war file. The goal of Maven is to generate this war file. Check if the file is indeed in the war file generated by Maven.
The appropriate location for such a file in a Maven project is /myapp/src/main/resources/displaytag.properties. The files in this location are considered as resources which must be copied along with the classes in the generated artefact. If it's not the case, it means that the resources plugin isn't used, or is configured in a way that excludes this file or gets resources from another directory.
I constantly get:
mf.mwe2.launch.runtime.Mwe2Launcher - Couldn't find module x
error though the x.mwe2 file exists. I have enabled the xtext nature to the project and added related modules.
here's the .mwe2 file:
module com.ford.modelling.workflow.abcd
Workflow {
component = SayHello {
message = "hello"
}
}
What might be the problem? (a folder named src-gen already exists)
please make sure that the mwe2 file is placed in a java source folder and that you did a clean build on the project the mwe2 file is contained.
Had the same problem. The exception however occurs in the Mwe2Runner, not the Mwe2Launcher. The Mwe2Runner tried to load the mwe2 file as a resource and produces that error if it can't find it, although the Mwe2Launcher can.
Anyway, solution is to register your src-dir as a resource-dir by adding the following to your pom.xml
<build>
...
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
...
</build>
OK. I've found the problem (though not a solution yet).
Enabling scala nature halts the build process of MWE2. Can't figure out why but this is what happens. I remove the Scala nature and everything works.
I am working on a gwt module that is built using maven build system. I
had a working module that had the following project structure.
project-name/src/main/java/pkg1/pkg2/pkg3/EntryPoingClass
project-name/src/man/resources/pkg1/pkg2/ModuleDef.gwt.xml
The module definition was looking like this (I have put only this
project specific settings here...normal inherits are not specified for
the sake of brevity)
... <entry-point class='pkg1.pkg2.pkg3.EntryPointClass'/>
<source path='pkg3'/>...
I am not a big fan of having sub packages in the resources folder.
Hence I am trying to change it to something like the following
project-name/src/main/java/pkg1/pkg2/pkg3/EntryPoingClass project-name/src/man/resources/ModuleDef.gwt.xml
Also changed the module definition to
... <entry-point class='pkg1.pkg2.pkg3.EntryPointClass'/>
<source path='pkg1.pkg2.pkg3'/> <!-- Since the module def is not
inside any package I am specifying the entire 'client' package here --> ...
After this, invoking gwt compile fails with the following error
Unable to find type "pkg1.pkg2.pkg3.EntryPointClass"
Can anybody tell me if there is any relation between the package
structure of the EntryPointClass and the module definition package
structure apart from the fact that the EntryPointClass should be
inside the 'client' package specified in the module definition (which
is satisfied here)?
Btw, I could see that the compiled classes are available in the
classpath when invoking the gwt compiler.
Any help in this regard is greatly appreciated.
GWT compiler needs sources of client side classes, not only compiled bytecode. Is it in classpath?
In my company we always set pom.xml to copy sources to target as resources:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/client/**/*.java</include>
<include>**/*.gwt.xml</include>
</includes>
</resource>
</resources>
</build>
Change **/client/**/*.java to anything satisfies your needs (probably pkg1/pkg2/pkg3/**/*.java). This way sources of client part are always in classpath.
I have a maven project and I'd like to create a distribution of it with the dependencies. I've tried the maven-assembly-plugin and built the jar with dependencies, but that unpacked all of the jars and repackaged them all into a big, single jar. What I'd like is something like my jar file and a lib folder that has all of the dependencies. Then when I run it, I could run "java -cp lib/* my.package.MainClass".
What's the best way to go about doing this with maven? Or the recommended way to deploy?
thanks,
Jeff
I have used the Maven assembly just for that in my project.
First enable your plugin in your POM and call your assembly config :
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<!--I recommend 2.1 as later versions have a bug that may
Duplicate files in your archive
-->
<version>2.1</version>
<!--Executes the packaging along with the mvn package phase
-->
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>attached</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptors>
<!--Relative path to your descriptor -->
<descriptor>src/main/assembly/package.xml
</descriptor>
</descriptors>
</configuration>
</plugin>
Then in your descriptor you can decide how you want your layout to be before you package the whole thing
<assembly>
<!-- this will create an extra resource project-1.1.1-package.zip, you can
choose jar as well in the format-->
<id>package</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<!-- Insert here extra files as configs or, batch files, resources, docs etc-->
<fileSets>
<fileSet>
<directory>src/main/assembly/files</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>**/conf/*.*</include>
<include>**/doc/*.*</include>
</includes>
</fileSet>
<!-- I like to integrate the jre as well... simplifies my deployement -->
<fileSet>
<directory>target/jre</directory>
<outputDirectory>/jre</outputDirectory>
</fileSet>
</fileSets>
<!-- This will scrub your dependencies and add them to your lib folder, I excluded
Test stuff as it is not needed, could have declared the resource as a test
only phase as well would not have had to exclude it here
-->
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<excludes>
<exclude>junit:junit</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>
This will create a zip file with the layout you have specified in your output directory config, package the whole thing as a zip file (you can choose zip, jar, war ...) and deploy it in my repository with the rest.
I skipped bits and pieces to make it simpler but my package expands to include batch files, dlls, config, doc and the JRE so everything needed is in the same zip... all is needed to run the thing is extract and click start.bat !
I could also probably make it in to a jar properly formatted with METADATA and just double click the jar itself to start it all, I did not need or have time to toy around this option but you may try it as well.
Beware of versions above 2.1 of the assembly plugin, it will create duplicate entries if your directives enable it to find the same file in different locations, this will give you a lib folder with the same jars repeating twice. not very dangerous as unzipping will collapse them but still annoying to have the unzip ask you if you want to overwrite files. Plus the fact that you do not know which won if somehow they turned out to be different in content.
Maven is great but I find that it is sometimes frustrating to get it working, Plus documentation can sometimes be hard to find and use. However, used appropriately it will save you tons of time.
good luck
See:
http://maven.apache.org/shared/maven-archiver/index.html
You should be able to use the maven-jar plugin to package up an archive, specify the main class to execute along with the classpath. It can generate a manifest file for you for your project.
http://maven.apache.org/shared/maven-archiver/examples/classpath.html#Prefix