Mostrando entradas con la etiqueta What if. Mostrar todas las entradas
Mostrando entradas con la etiqueta What if. Mostrar todas las entradas

miércoles, 18 de mayo de 2011

What if I want to deploy/upload several files to artifactory or nexus with Maven?

Regardless of the repository you are using to store generated artifacts, the default Maven configuration for, let's say, WAR file, is upload a WAR file.. interesting..

A common configuration commented here also uploads the source code as a jar file, and that is very recommendable for debugging.

Another uploaded or auto-generated file is a "pom.xml" project descriptor file for your artifact.

But we want to go further, we want to upload the sql file needed to generate our initial database, or the pdf with the documentation of this release.. how to get this?

<plugin>   
  <groupId>org.codehaus.mojo</groupId>   
  <artifactId>build-helper-maven-plugin</artifactId>
  <executions>
    <execution>

      <id>attach-artifacts</id>
      <phase>package</phase>
      <goals> 

        <goal>attach-artifact</goal>
      </goals> 
      <configuration>
        <artifacts> 
          <artifact> 
            <file>src\main\sql\initdb.sql</file>
            <type>sql</type>
            <classifier>create</classifier>
          </artifact>
          <artifact>
            <file>target\site\docs\document.pdf</file>   
            <type>pdf</type>
            <classifier>doc</classifier>
          </artifact>
        </artifacts>
      </configuration>
    </execution>
  </executions>
</plugin>


With this plugin, you are associating with the same artifact the "document.pdf" file, the "initdb.sql" file, the war, the sources jar, the pom.xml file... all them with the same version, and with the possibility of declaring any of them as a dependency.

It will be executed in package phase, beware because you may mistake the phases and attach something not yet created, for example, the pdf may be created in pre-site phase instead of .. compile, for example.

In the case of multiple configurations, you can configure it like this:


<plugin>   
  <groupId>org.codehaus.mojo</groupId>   
  <artifactId>build-helper-maven-plugin</artifactId>
  <executions>
    <execution>

      <id>attach-artifacts1</id>
      <phase>package</phase>
      <goals> 

        <goal>attach-artifact</goal>
      </goals> 
      <configuration>
        <artifacts> 
          <artifact> 
            <file>src\main\sql\initdb.sql</file>
            <type>sql</type>
            <classifier>create</classifier>
          </artifact>
        </artifacts>
      </configuration>
    </execution>

    <execution>
      <id>attach-artifacts2</id>
      <phase>site</phase>
      <goals> 

        <goal>attach-artifact</goal>
      </goals> 
      <configuration>
        <artifacts> 
          <artifact>
            <file>target\site\docs\document.pdf</file>   
            <type>pdf</type>
            <classifier>doc</classifier>
          </artifact>
        </artifacts>
      </configuration>
    </execution>

  </executions>
</plugin>

In this case, if we execute "mvn deploy", only "initdb.sql" will be attached, if we execute "mvn site-deploy", it will be only attached "document.pdf" (because it is supposed to be created in pre-site phase, but I am not sure if it will be deployed in "artifactory" or "nexus", because you don't pass through "deploy" phase, I would say it won't.

The best, if you execute "mvn site-deploy deploy", firstly "document.pdf" is attached in "site" phase, then "initbd.sql" is attached in "package" phase, and finally all them are deployed in "deploy" phase. Really useful!

This is the solution for a problem we wanted to solve in my job, the solution was taken here, thanks!

viernes, 7 de enero de 2011

What if... I get a "Fileset from project [projectname] has no valid check configuration" Error?

Content:
CheckStyle Eclipse plugin. Installation
Tunning your CheckStyle and Formatter
Every programmer working as only one
What if... I get a "Fileset from project [projectname] has no valid check configuration" Error?
CheckStyle configuration distribution

One solution for the following error:

Errors occurred during the build.
Errors running builder 'Checkstyle Builder' on project [projectname].
Fileset from project [projectname] has no valid check configuration.
Fileset from project [projectname] has no valid check configuration.
Fileset from project [projectname] has no valid check configuration.
Fileset from project [projectname] has no valid check configuration.




Analysis: 

It looks like to me that you configured CheckStyle in a workspace scope (Window->Preferences->CheckStyle...). Any of your team did the same, but his/her configuration, although it is the same, he/she put a different name to the configuration.

The other person generated a checkstyle project configuration, like ignored folders, and shared it with you, through Subversion for example.

As soon as you get that configuration, Checkstyle search for a specific configuration name, your pal's one, and yours name is different. That's the error.


Solution:

Please check your .checkstyle file in the root folder of the project. Specially "fileset" node, "check-config-name" property. Its value MUST be coherent with your CheckStyle configuration name. That file must be under version control repository Subversion and is shared between developers, so it is possible that some guy imported its workspace configuration.

Example of mistaken configuration .checkstyle file:

<?xml version="1.0" encoding="UTF-8"?>
<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
  <fileset name="all" enabled="true" check-config-name="Sun Checks" local="false">
    <file-match-pattern match-pattern="." include-pattern="true"/>
  </fileset>
  <filter name="WriteProtectedFiles" enabled="true"/>
</fileset-config>



Coherent CheckStyle configuration at Window menu -> Preferences.


If the configuration doesn't defaults to the same name, or a project local configuration doesn't either, the error will appear. Check both IDE and project checkstyle configuration.

For avoiding the same error in the future, you can agree a name for that configuration with your team. A possible better solution is described here, and consist of configuring CheckStyle inside the project, and such information will travel with it, no more name mistaken will happen.


Did it work? Leave a comment.

See you! :)

martes, 14 de diciembre de 2010

What if... I create a Maven web application and Tomcat doesn't see it?

Content:

Maven abstract.
Tunning your Maven proyect
Maven standard folders
Managing dependencies with Maven
Adding a nature in Eclipse
Maven profiles inheritance

It's hard for me to replay this error in my well configured computer :P, but I found something useful.

You need to add a "Dynamic Web Module" in Project "Properties" -> "Project Facets".
Then F5 and try to "Run as.. Run on Server".

If I create a Maven Web Project (maven-archetype-webapp in the second configuration window on "New Maven Project", I can read inside my .project file:


<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature> 
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>


As said in this web, if I delete the bold line, the option of running on server dissappears, so, it could be a nice clue.

If I try to read active facets in the "Project Facets" property page, I find this:

"This project is not configured to use project facets. Converting this project to faceted form will allow you to easily control the available technologies."

If I accept its proposal, then the bold line reappears! Mmmmm, interesting, isn't it?

That information is coded in ".settings/org.eclipse.wst.common.project.facet.core.xml"

Face and Unface "Dynamic Web Module" and check that file out to find how it works.


Have a nice day   :)