Danny Lo
Danny Lo

Reputation: 1583

How to include uncompiled java files in a JAR built by Tycho?

I have a source root with *.java files, but I don't want them to be compiled. Instead, the *.java files should be copied into the jar as they are. The use case for this is that the *.java files are templates and hence should be preserved as they are.

To achieve this, I tried to exclude a source folder from compiling phase of my build and I am quite confused by the official documentation to the Tycho OSGi Compiler Plugin. It says I can use parameter excludeResources but I don't really know how to handle all these parameter types. pom.xml is a structured text file and not a source file, that's why I don't understand how to use java.util.Set for that parameter.

My POM goes like this:

...
<build>
    <plugins>
        ...
        <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>tycho-compiler-plugin</artifactId>
            <version>0.21.0</extensions>
            <configuration>
                <excludeResources>
                    <!-- Set of folders consisting of a source folder named "res"
                         which should be excluded completely from compilation -->
                </excludeResources>
            </configuration>
        </plugin>
    </plugins>
</build>

Is it a right approach? If yes, how would I complete the configuration?

Upvotes: 1

Views: 702

Answers (2)

jsievers
jsievers

Reputation: 1853

If you want to exclude a whole source root folder from compilation, simply do not add it to any of the src.* entries in build.properties, see [1]

If on the other hand you want to include the *.java files in the source root folder in the resulting jar, add the root folder to the list of bin.includes in build.properties.

excludeResources is unrelated to your problem, as the docs you linked say:

"A list of exclusion filters for non-java resource files which should not be copied to the output directory."

[1] http://eclipse.org/tycho/sitedocs/BuildProperties.html

Upvotes: 0

user3926784
user3926784

Reputation:

Try something like this to remove any occurences of "res" folder and files:

<plugin>
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>tycho-compiler-plugin</artifactId>
        <version>${tycho-version}</version>
        <configuration>
                <excludeResources>
                        <excludeResource>**/res</excludeResource>
                </excludeResources>
        </configuration>
</plugin>

or this, alternatively, for example, to include the "res" folder and exclude .jar files:

<plugin>
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>tycho-compiler-plugin</artifactId>
        <version>${tycho-version}</version>
        <configuration>
                <includes>
                    <include>res</include>
                </includes>
                <excludes>
                    <exclude>**/*.jar</exclude>
                </excludes>
        </configuration>
</plugin>

Or, to exclude everything that is not the "res" folder:

<plugin>
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>tycho-compiler-plugin</artifactId>
        <version>${tycho-version}</version>
        <configuration>
                <excludeResources>
                        <excludeResource>!**/res</excludeResource>
                </excludeResources>
        </configuration>
</plugin>

Upvotes: 1

Related Questions