Symbol and Packages not found

I am trying to compile a Github repository, https://github.com/GrammarViz2/grammarviz2_src. However, when I run the application on CMD, I get the error-

    GrammarVizGUI.java:4: error: package net.seninp.grammarviz.controller does not exist
import net.seninp.grammarviz.controller.GrammarVizController;
                                       ^
GrammarVizGUI.java:5: error: package net.seninp.grammarviz.model does not exist
import net.seninp.grammarviz.model.GrammarVizModel;
                                  ^
GrammarVizGUI.java:6: error: package net.seninp.grammarviz.view does not exist
import net.seninp.grammarviz.view.GrammarVizView;
                                 ^
GrammarVizGUI.java:17: error: cannot find symbol
  private static GrammarVizModel model;
                 ^
  symbol:   class GrammarVizModel
  location: class GrammarVizGUI
GrammarVizGUI.java:20: error: cannot find symbol
  private static GrammarVizController controller;
                 ^
  symbol:   class GrammarVizController
  location: class GrammarVizGUI
GrammarVizGUI.java:23: error: cannot find symbol
  private static GrammarVizView view;
                 ^
  symbol:   class GrammarVizView
  location: class GrammarVizGUI
GrammarVizGUI.java:48: error: cannot find symbol
    model = new GrammarVizModel();
                ^
  symbol:   class GrammarVizModel
  location: class GrammarVizGUI
GrammarVizGUI.java:51: error: cannot find symbol
    controller = new GrammarVizController(model);
                     ^
  symbol:   class GrammarVizController
  location: class GrammarVizGUI
GrammarVizGUI.java:54: error: cannot find symbol
    view = new GrammarVizView(controller);
               ^
  symbol:   class GrammarVizView
  location: class GrammarVizGUI
9 errors

However, on closer examination I see that many of the packages are present within the source, inside multiple folders. I have almost zero experience with running Java code, hence I believe that I must be making some silly error.

Answer

There are some things missing, let’s do it step by step:

There is missing a jar-plugin configuration (assembly plugin configuration is not sufficient to provide Main-Class in MANIFEST.MF

Add this plugin configuration into profile single

...
<profile>
    <id>single</id>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.5.4</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>net.seninp.grammarviz.GrammarVizGUI</mainClass>
                        </manifest>
                    </archive>
                    <!-- <filters> <filter>src/assembly/filter.properties</filter> </filters> 
                        <descriptors> <descriptor>src/assembly/distribution.xml</descriptor> </descriptors> -->
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id> <!-- this is used for inheritance merges -->
                        <phase>package</phase> <!-- bind to the packaging phase -->
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>net.seninp.grammarviz.GrammarVizGUI</mainClass>
                        </manifest>
                    </archive>
                    <!-- <filters> <filter>src/assembly/filter.properties</filter> </filters> 
                        <descriptors> <descriptor>src/assembly/distribution.xml</descriptor> </descriptors> -->
                </configuration>

            </plugin>
        </plugins>
    </build>
</profile>
...

Then You need to use this profile during build:

mvn -Psingle clean package
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 18.949 s
[INFO] Finished at: 2019-03-21T21:30:25+01:00
[INFO] Final Memory: 28M/435M
[INFO] ------------------------------------------------------------------------

It creates 2 jar files in target directory:

grammarviz2-0.0.1-SNAPSHOT.jar
grammarviz2-0.0.1-SNAPSHOT-jar-with-dependencies.jar

Then You need to run the application (from target directory):

java -jar grammarviz2-0.0.1-SNAPSHOT-jar-with-dependencies.jar

This jar contains a MANIFEST.MF file (/META-INF/MANIFEST.MF) which was configured above in pom.xml with proper entries to run this jar as an application without providing main class.

“Works on my machine”:

java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

Linux Mint 18.3

Leave a Reply

Your email address will not be published. Required fields are marked *