I am autogenerating my wsdl using spring-ws and an XSD. Now I would like to generate java classes to return and do marschalling.
However I am seeing a lot of different ways to accomplish this, and not all are as clear about the benefit\detrement.
Some just save the generated WSDL in their project, others use their XSD file to generate, others add XJB etc...
My first thought was just adding:
<plugin>
<groupId>com.sun.tools.xjc.maven2</groupId>
<artifactId>maven-jaxb-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<removeOldOutput>true</removeOldOutput>
<schemaDirectory>src/main/webapp/WEB-INF</schemaDirectory>
</configuration>
</plugin>
to my pom.xml
My preferred way is jaxb2-maven-plugin. See http://mojo.codehaus.org/jaxb2-maven-plugin/usage.html
It's actually using XJC, a command that now comes with your current JDK (under bin in Windows or Commands in Mac)
You can call it directly with xjc -p your.package -wsdl your.wsdl
to use maven to generate java code from WSDL, you can check maven cxf codegen plugin wsdl to java.
Related
I am writing an Aspect in Mavenised project. PROJECT_A
Now I want to use the PROJECT_A.jar in PROJECT_B which is non mavenised.
And in PROJECT_B i want to use the annotaition which I have written using the aspect in PROJECT_A .
I tried exporting PROJECT_A.jar - with aspectJ Plugin as follows. But when i use it in PROJECT_B - my annotation does not works as expected.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
I am new to the use of AspectJ and I am not getting how to do it without maven in PROJECT_B.
Please help , any help is appreciated :)
First of all, upgrade to AspectJ Maven 1.9.
Then mavenise project B! This enables you to you can use AspectJ Maven plugin to weave the aspects into your other module, even after compilation. This is called binary weaving. Please read the plugin documentation, especially the info about parameters aspectLibraries and weaveDependencies, depending on which approach you want to pursue.
Alternatively, start your JVM with -javaagent:/path/to/aspwctjweaver.jar and use the AspectJ weaving agent for load-time weaving (LTW). But do not forget then to also provide a LTW configuration via META-INF/aop.xml.
Either way, you have options. But both require you to read some documentation or at least search this site for examples.
I have an application which I want to deploy in karaf. I have created a feature file and I am able to add features through this file using karaf console. What I want to achieve now is that create this feature file through maven commands instead of creating it manually and then create a custom karaf distribution using this feature file. How can I achieve it ?
My approach so far is to create a maven module for generating feature file using karaf-maven-plugin and then create another module to generate karaf custom distribution so that we dont need to access maven in production environment.
Is this approach correct ? Do I really need to make two different modules for achieving it. How can I get access to feature file from second module.
These are my poms -
all dependecies
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<version>4.0.5</version>
<extensions>true</extensions>
<executions>
<execution>
<id>generate</id>
<phase>generate-resources</phase>
<goals>
<goal>features-generate-descriptor</goal>
</goals>
<configuration>
<startLevel>80</startLevel>
<aggregateFeatures>true</aggregateFeatures>
<includeTransitiveDependency>true</includeTransitiveDependency>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I am not able to figure out the second part yet. Any help with that is really appreciated.
To generate a custom Karaf you just need to use the karaf-maven-plugin.
For example the following will generate a fully working custom Karaf:
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<version>4.0.0</version>
<extensions>true</extensions>
<configuration>
<!-- no startupFeatures -->
<bootFeatures>
<feature>minimal</feature>
</bootFeatures>
<installedFeatures>
<feature>wrapper</feature>
<feature>spring/4.0.7.RELEASE_1</feature>
</installedFeatures>
</configuration>
</plugin>
This will generate a custom karaf based on the minimal sets of features which are needed to create the minimal distro. If you want to depend on the standard distro just exchange that with standard.
Btw. all this is also documented in the Karaf documentation
When using cargo to deploy to a remote server I would like to check with cargo or maven that the generated war have it's properties files filtered like expected.
Some phase in between should test a property file from war against some strings and so deploy or stop deployment.
there's built in on cargo to achieve this?
Not sure what are the properties files you're referring to therefore I assume that you refer to typical java *.properties files.
Anyway, I believe you should use: maven-enforcer-plugin and it's goal: enforce as that is the common way in maven to enforce some condition (the plugin uses term: rule) to be fulfilled.
I think you have more options here.
Option 1
Maybe you could check that prio to packaging to your war using:
maven-property-plugin - goal: read-project-properties (http://mojo.codehaus.org/properties-maven-plugin/usage.html)
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>???</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>your_file_to_check.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
where you should:
check the right phase to make sure the file is already filtered (http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html)
reference the file you want to check the properties of
And afterwards go for maven-enforcer-plugin goal: enforce and the rule: requireProperty (http://maven.apache.org/enforcer/enforcer-rules/requireProperty.html)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>enforce-property</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireProperty>
<property>your_property_to_check</property>
<message>You must set a your_property_to_check property!</message>
<regex>regex</regex>
<regexMessage>violation txt</regexMessage>
</requireProperty>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
where:
your_property_to_check should be replaced with the real one as well as
regex should be defined
Option 2
If that is not feasible and you want to check property inside war file, you might need to write your own rule.
That should not be a big deal as java has zip reading as well as properties files loading in it's standard API. To learn how to write custom rule, see: http://maven.apache.org/enforcer/enforcer-api/writing-a-custom-rule.html
Btw. I'd be quite curious to understand why would someone want to do check some property on each deployment? Is the case that your input (property files you filter) are dynamically generated/changed? Otherwise I doubt you need it once you check it works.
I have gwt web project, which must use application.properties (on client side) loaded as TextResource in the code. Everything works fine, but now i want to centralize all properties values in maven pom.xml. So i made application.properties with placeholders like key1=${param1} and in the pom.xml i configured property param1Value
So, what happening is that maven replaces the placeholders in application.properties in target dir, but it seems that gwt compiler uses the application.properties file from src/main/resources. I checked the compiled js files and i there i can see that the placeholder is not replaced with its value from the pom.xml (target's application.properties is correct).
UPDATE:
The problem is that, the properties file I am filtering is a gwt messages resources bundle file and from what I saw, maven creates a "generated" folder and puts a generated java file based on the properties file found in the root project sources folder and not in the target folder. After that, it incorporates it in the javascript general file.
This means I have two possibilities:
1) tell the resources plugin to overwrite the properties file located in the sources folder (I am not cool with that because I will certanly have problems on the next subversion update)
2) tell gwt-maven-plugin to seek the properties file in the target/classes folder which I think it is impossible
What do you think ?
I resolved the same problem by using resources:copy-resources execution and build-helper plugin.
In particular, configure the resources plugin:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>filter-sources</id>
<goals>
<goal>copy-resources</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<outputDirectory>${project.build.directory}/gwt-extra</outputDirectory>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/filtered-sources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
and include it using build helper:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source-gwt</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/gwt-extra</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
I managed to use maven filtering on properties files used in GWT compilation.
I use the com.google.gwt.i18n.client.Constants interface.
It allows to instanciate an interface that extends Constants, with methods returning values taken from a properties file.
That properties file can be process by maven filtering.
It's really easy to do :
declare an interface extending Constants : XxConstants
create a properties file XxConstants.properties in src/main/resource in the same package as your interface
activate maven resources filtering so XxConstants.properties is filtered
when GWT is compiling (with gwt-maven-plugin), it will generate an instance of XxConstants using the filtered properties file.
in your gwt code, create an instance of XxConstants with GWT.create or with gin injection
call the methods to get the property values
One caveat : filtering is not working in gwt dev mode
Result can be check in the target.generated folder whiwh will contained the java implementation of the interface with the filtered properties used.
Problem:
I'd like to specify the main class in a jar file that I am packaging using m2eclipse: [right-click] -> Run As -> Maven package. I'm still learning Maven and from what I've read, the straight-up way of accomplishing this task is to add a stanza to the pom.xml.
Here are examples I found when I was researched this issue:
Cannot make executable jar using m2eclipse
http://docs.codehaus.org/pages/viewpage.action?pageId=72602
My question is this: is it okay to manually edit the pom.xml file outside of Eclipse/m2eclipse using a text editor, or should I be doing this configuration using the m2ecplise GUI? There are several tabbed dialog boxes that seem like they might be likely candidates for this task, like "Plugins" and "Build". I looked through Sonatype's documentation and couldn't find any detailed instructions on how to accomplish what I need to do.
I'm a little hesitant to edit the pom.xml manually because I notice the "Effective POM" already has a lot of extra stuff in it, including the plugin definition that needs to have added to it:
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>default-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
If I understand correctly, the Effective POM needs to be changed so that the plugin is configured like this:
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>default-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<mainClass>[name of main class]</mainClass>
<packageName>[package name]</packageName>
</manifest>
<manifestEntries>
<mode>development</mode>
<url>${pom.url}</url>
</manifestEntries>
</archive>
</configuration>
</plugin>
Is this right? And if so, do I do this through m2eclipse or should I just copy all the extra Effective POM stuff and paste it into the actual pom.xml using a text editor?
Thanks to anyone who can shed some light.
UPDATE: I went ahead and manually edited the pom.xml file in a text editor. When I viewed Effective POM in m2eclipse it displayed everything that I put in (I assume). I built the jar and the main class was correctly set.
This seems like a hack to me though. Does anyone know if there's a way to do this configuration using m2eclipse itself? I checked the m2eclipse tabs and nothing seemed to have been updated as a result of my manual edits of pom.xml (other than the Effective POM tab).
m2eclipse doesn't do everything for you, i.e. there isn't a pretty UI tab for handling everything.
My team is most comfortable with editing the POM manually, and using the other tabs for verification (like Effective POM view).