0

I want to obfuscate a project (jar) using ProGuard (Project A). However, this project is dependent on another war (Project B) and uses some of the classes I have developed in B. I used the solution from this question: Build a jar from a maven project dependent on other project but it did not work and when I use the command maven clean install -X on Project A I get the error:

error: cannot find symbol

or

error: package com.example does not exist

How can I obfuscate this jar?

Edit 1

In POM of Project A I have:

  1. my war dependency:

    <dependency>
        <groupId>com.example</groupId>
        <artifactId>myWarProject</artifactId>
        <version>1.0.0-BUILD-SNAPSHOT</version>
    </dependency>
    
  2. in build section:

       <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <finalName>DeviceListener</finalName>
                        <transformers>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <manifestEntries>
                                    <Main-Class>com.example.main.Main</Main-Class>
                                    <Build-Number>1</Build-Number>
                                </manifestEntries>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    

In Project B I have:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.2.0</version>
            <configuration>
                <attachClasses>true</attachClasses>
            </configuration>
        </plugin>
yassadi
  • 524
  • 1
  • 9
  • 20

1 Answers1

0

I mean to create a jar of the classes which are in the war project like this:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.0.0</version>
            <configuration>
                <attachClasses>true</attachClasses>
                <archiveClasses>true</archiveClasses>
            </configuration>
        </plugin>
    </plugins>
</build>

This produces a supplemental jar file which contains the classes of the war project which can be used as dependency (not forgetting to define the classifier)..

You need to change your dependency like this:

<dependency>
    <groupId>com.example</groupId>
    <artifactId>myWarProject</artifactId>
    <version>1.0.0-BUILD-SNAPSHOT</version>
    <classifier>classes</classifier>
</dependency>
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • Yes I have tried this and still got the same error. – yassadi Feb 14 '18 at 08:48
  • Thanks a lot, although I'm getting Error code 403, Forbidden now. Considering the projects are both in the same workspace, why would this be happening? Thank you for your help. – yassadi Feb 14 '18 at 11:00