views:

263

answers:

7

Hi, I am new to Maven2 and have been having an issue with the compiling of the source for a RAR. Maven currently copies all the information located at my sourceDirectory instead of compiling it even though the console states that the source is being compiled. If I navigate to the sourceDirectory I find all my source files with no compiled class files. I have tried changing my outputDirectory to a different location and when I inspect this directory I find that it only copied my source files instead of compiling them. I have added an example of my POM. Any advice would be appreciated and please keep in mind I have only started learning/implementing Maven2 yesterday :)

    <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
  <modelVersion>4.0.0</modelVersion>
  <artifactId>MyApp</artifactId>
  <groupId>.</groupId>
  <version>4</version>
  <packaging>rar</packaging>
  <name>MyApp rar</name>
  <build>
    <directory>target\${artifactId}-${version}</directory>
    <resources>
        <resource>
            <directory>..\gen-src</directory>
            <excludes>
                <exclude>util.jar</exclude>
            </excludes>
        </resource>
        <resource>
            <directory>..\domain</directory>
        </resource>
    </resources>
    <sourceDirectory>target\${artifactId}-${version}</sourceDirectory>
     <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-rar-plugin</artifactId>
        <configuration>
            <workDirectory>target\${artifactId}-${version}\classes</workDirectory>
            <outputDirectory>target</outputDirectory>
            <finalName>MyApp${version}</finalName>
            <raXmlFile>${workDirectory}\META-INF\ra.xml</raXmlFile>
        </configuration>
      </plugin>
    </plugins>  
  </build>
</project>
+1  A: 

By default, Maven puts the compiled class files into target/classes. I would try running the rar plugin with the default settings (i.e. removing the <directory>, <resources> and <sourceDirectory> elements from your build section, also the <configuration> of the plugin) and see what it does - I strongly believe it should pack the class files in this case. If this works, then you can start modifying its config, one step at a time, to finetune your build.

Why do you actually want to pack the source files into the RAR?

Péter Török
+2  A: 

Ok couple of things with regard to your pom that you may want to consider.

  1. Change your groupId from . to something more meaningful, com.foo? Try using the first two elements of your package names to fill it in.
  2. change your \ to / ... It won't matter which platform you're on as maven / java will handle it properly.

Read up a bit more on maven's convention-over-configuration approach. There are two great resources that I've used for years now that are indispensable

  1. The Maven Book from Sonatype
    http://www.sonatype.com/products/maven/documentation/book-defguide
  2. Better Builds with Maven
    http://www.maestrodev.com/better-build-maven

I noticed a number of things you're doing that would be Ant related, but with Maven they're kind of done for you. Read over the links I've posted above and hopefully that will get you pointed in the right direction.

In most cases you won't have to kill yourself to get it to pickup source, generated code, etc.

Dave G
+1  A: 

You need not to specify the resources dir etc. maven is not ant, its way more "clever", if you started with maven yesterday .. make sure you read maven by example, its a free ebook really good book to get you acquainted with maven. Its not hard or complicated, really plain and simple. I myself started with a maven not a month ago, that was the first book I read, just after few chapters you get some basic points, after that you need a bit more reading and some practice. I'm still reading some maven books, and use it on daily basis and still encounter problems I don't know the answer to .. but there are people that can help..

c0mrade
+2  A: 

Maven embraces the idea of Convention over Configuration and comes with lots of defaults. If you want to use Maven, you should really adopt its philosophy and conventions, it will save you a lot of work (and pain). So instead of overriding all locations, you should change your current layout and follow Maven's Standard Directory Layout: source code is assumed to be src/main/java, resources are assumed to be in src/main/resources, tests are assumed to be in src/test/java, the ra.xml is assumed to be in src/main/rar/META-INF, etc.

Move your various files, your project layout should looks like this:

$ tree .
.
|-- pom.xml
`-- src
    |-- main
    |   |-- java
    |   |   `-- com
    |   |       `-- stackoverflow
    |   |           `-- q2408715
    |   |               `-- App.java
    |   |-- rar
    |   |   `-- META-INF
    |   |       `-- ra.xml
    |   `-- resources
    `-- test
        |-- java
        |   `-- com
        |       `-- stackoverflow
        |           `-- q2408715
        |               `-- AppTest.java
        `-- resources

Once you've done that, remove all the useless <directory>, <resources>, <sourceDirectory>, <workDirectory>, <outputDirectory>, <raXmlFile> garbage from your POM that should look something like this (fix the groupId in the same time):

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.stackoverflow.q2408715</groupId>
  <artifactId>q2408715</artifactId>
  <version>1.0-SNAPSHOT</version>
  <name>My Resource Adapter</name>
  <packaging>rar</packaging>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    ...
  </dependencies>
  <build>
    <plugins>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-rar-plugin</artifactId>
      <configuration>
        <finalName>MyApp${version}</finalName>
      </configuration>
    </plugins>
  </build>
</project>

I'm not sure what util.jar is exactly so it's hard to say anything about it but it probably shouldn't be there. Also, I don't know if you are really generating sources but if you are, the standard is to generate them in target/generated-sources/<tool>.

Don't hesitate to refer to the Maven RAR plugin page for more options and pay a special attention to the Examples section.

And if you need more guidance, please at least apply these changes and then update your question with more specific problems to solve.

Pascal Thivent
Thanx for the input, please see my post to the bottom, it might clarify the situation some.
Grep
@Grep No problem. Did this help? Are you getting the expected result now?
Pascal Thivent
A: 

Thanks for the prompt reply; the problem is I am not able to change the directory structure. We currently use ant to package our EAR and we do have a "unique" directory structure. The POM currently resides in a build directory inside the project, so I was forced to make use of the above supplied configuration. I should be able to modify the super POM which will enable me to remove the current additional directory tags, but I would rather have a default configuration of MAVEN2 work for all others. I have noticed that the util.jar is in the wrong place and I have informed my superiors prior to my original post. I have also attempted to use the compiler plug-in, and get the exact same results. MAVENs console displays the source code being compiled, but the destination still only contains the source files, it merely copied them.

Sorry for not replying to all of your your answers, it appears I have too much to say :)

Grep
A: 

Peter,

In your particular case (with the additional details you provided), look definitely at the Better Builds With Maven book. It goes on a deep dive into the properties that control the build conventions.

It should provide you with enough detail to get this functioning the way that you want.

Dave G
A: 

Try removing <packaging>rar</packaging>

Lukas Vlcek