I develop my project in Eclipse with standard Maven directory layout. Sources are in src/main/java/com/mycompany directory. And it is required to put my source classes in package main.java.com.mycompany. When I build executable jar-file, I have to define the main class in Manifest.MF like:
Main-Class: main.java.com.mycompany.MyMainClass
But I saw in a lot of examples (like configuring the mainClass attribute in maven-assembly-plugin or maven-jar-plugin) that class names are specified without main.java part. I just want to have
Main-Class: com.mycompany.MyMainClass
I can't figure out how I can achieve this because I'm completely novice in Maven.
While creating a maven project if you have mentioned values for both groupId and package name, then maven will consider the package name to place your java class. For example: mvn archetype:generate -DgroupId=gen.src -DartifactId=Iftekhar -DpackageName=com.src.Model -Dversion=2.0-Snapshot. In the above scenario App.
Package names are written in all lower case to avoid conflict with the names of classes or interfaces. Companies use their reversed Internet domain name to begin their package names—for example, com. example. mypackage for a package named mypackage created by a programmer at example.com .
Step 4: Now right-click on the first package name (com) and Refactor > Rename. A warning message will be displayed but go ahead and click on the Rename current button. Step 5: Rename the directory name as your requirement and click on the Refactor button. Note: Go to Build > Rebuild Project to display the updated name.
Maven's default directory layout differs from the layout Eclipse uses when you create a new Java project.
It's actually pretty simple. When you create a new Java project, Eclipse creates a folder named 'src' on your filesystem, where you should put your source code. Additionally, Eclipse configures this folder as a 'source folder'. Every folder you create in this folder will represent a Java package.
What Maven wants is a little bit different. Maven likes you to have a 'src/main/java' folder with the 'java' subfolder configured to be a source folder. Hence, all folders created under this java folder will represent Java packages.
You can manage your source folders in Eclipse from your project properties. Right click your project, select 'build path -> configure build path'. In the popup open the 'source' tab. Now, remove 'src' as a source folder and replace it with 'src/main/java'.
Now Eclipse will recognize your packages as com.mycompany instead of main.java.com.mycompany.
I always use the maven-eclipse plugin to generate my eclipse project and classpath files from the commmand line. I'm not a big fan of m2e.
You can also try updating the maven project. Right click on the project > Maven > Update Maven Project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With