Maven Eclipse Debugging - java

I created simple hello world program with Maven and Eclipse. I can Run and Debug as Java application. I was able to create configuration under Create,Manage,Run > Java Application as Helloworld. Within this configuration I could assign Project and class.
I have existing Maven project in Eclipse. This is significantly different. It does not appear with Package Explorer as a Maven or Java project, as it does not show any packages /src/main/java but as file folders (no icons for Maven or Java next to file folders).
When I click and attempt to configure this under Create,Manage,Run > Java Application, I am not able to browse to project or classes.
How would one go about Debugging this Maven project in Eclipse?
Project does have Create,Manage,Run > Maven Build configured. Compiles into Jar fine and pulls in necessary libraries with dependent pom XML.

I guess Eclipse does not know, that your Maven project is a Maven project.
You can change this as follows:
Right click with mouse on your project => "Configure" => "Convert to Maven Project"
This should trigger automatically a build and then you should see the Java and Maven icons.

Related

Java plugin for Visual Studio Code cannot load Spring Boot classes when start debugging a multi-module Maven project

I am using Visual Studio Code with Red Hat Java Plug-in and Debugger for Java plugin. I got a problem that:
1) If I work with a single module Maven project, everything is ok.
2) But if I open a multi-module Maven project, the debugger cannot start because of "java.lang.ClassNotFoundException: org.springframework.boot.web.servlet.support.SpringBootServletInitializer"
3) The project can be built with Maven, and running the Jar is all right
I guess the problem is because of the classpath settings, however to my understanding, the .classpath file should be derived from the POM file, which should be correct, otherwise Maven would have not been able to build the project.
I did not manually modify the launch.json, and the plug-ins generated the settings for me.

Combining a maven project with a java project

Currently, I have a maven project that has a server running (using Jersey REST API). I also have a java project, I need to move all the contents of the java project into the maven project. The maven project is a subset of the java project. However, the maven project only displays the parts of the java project. However, I want a project that allows me to use maven and displays all of the other details from the java project.
I would've copied and pasted however I'm using git so I want to also preserve history.
I was thinking it would be easier to nest the maven project inside the java project but I don't know if that's possible.
Here's a picture of my package explorer to help explain everything.
Package explorer showing the maven project being a subset of the java project.
What I've tried is converting the java project into a maven project and then updating the pom.xml but then it doesn't link to the web.xml. Also, it tries to run the server with the name of the project name TeamProject. When infact it should run the url with the name client_server
I was considering just copying and pasting all the code into the maven project (from the Teamproject java project).
Actually nesting the java project inside the Maven project makes more sense, as it is the purpose of Maven to handle a project lifecycle. (also by default Maven will look for sources in the src/ folder which should ease the task of putting your Java project inside Maven's hands)
There are several possibilities I would see:
Copy your java project in the src/ of your client project and update maven accordingly (within the pom.xml)
Make your Java project a Maven project and aggregate the two projects in a parent pom (see Multi module maven project example)
Make your Java project a Maven project, and decide of a "Master" project between it and the client and compose one with the other (not sure that's a great solution)
Nesting your Maven project inside the Java project would not be so great because Maven could only handle the client and not your Java project, and then you'd miss on numerous functionalities offered by Maven (just look at how simple it is to get dependencies compared to downloading a jar and including it on the build path manually)

Eclipse configuration to launch a Maven project with Google Web Toolkit

I'm starting a GWT project with web creator as following:
C:\>webAppCreator -noant -maven -overwrite -out MavenTest com.raphiki.MavenTest
It generates a Maven project's structure with an GWT Hello world project, I import this project in Eclipse as a Maven project with existing sources.
Then I enable Google Web Toolkit in my project, and I need to give a WAR path. I try with the /src/main/webapp which contains the entry point, but when I launch the app I get a ClassNotFoundException on Hello world's class's package.
See the following image which is the structure the WebAppCreator built:
Did I miss any configuration to do?
See http://web.archive.org/web/20130619170526/https://developers.google.com/eclipse/docs/faq#gwt_with_maven
TL;DR: run mvn package (or mvn war:exploded), then run DevMode, choose target/myapp-1.0-SNAPSHOT/ as webapp directory.
I can't speak for the webAppCreator because I haven't used it, but I have had good luck creating the Maven projects in Eclipse using the gwt-maven-plugin from codehause.
Creating a Maven GWT Project Directy in Eclipse
Open the new project wizard in Eclipse and filter on Maven Project.
Select the Maven Project and click next.
Enter the project location of your preference and click next.
Enter "gwt-" into the archetype filter and select the gwt-maven-plugin from codehaus. Click Next.
Enter your maven project details and a module value, then click Finish.
This will create a maven - gwt project for you in Eclipse. This comes with a sample application that you can use to make sure you can launch the application correctly.
Running the Application Command Line
Open command line.
Navigate to your project home.
Run the command "mvn clean package".
Run the command "mvn gwt:run"
This should get you up and running. If you used the 2.7.0 gwt-maven-plugin this should run the application in super dev mode by default.
Run the application in Eclipse
As you have done, navigate to Properties > Google > Web Application and check "This project has a WAR directory". The WAR directory using this plugin should be src/main/webapp.
Navigate to Properties > Google > Web Toolkit and check "This project has a WAR directory. You may be able to specify the module here. I am actually unable to do so, it may be specific to my Google Plugin for Eclipse or something environment specific...
Run As > Web Application.
If you had issues, as I have had, in step 2 then you will get an error Missing required argument 'module[s]'. To fix this open up your run configuration (should have been auto created) and in the arguments tab add the package qualified name for your module at the end of the arguments, e.g. com.mycompany.abc.GwtSampleModule. Do not add the ".gwt.xml" prefix.
It's worth also checking that the HTML page referenced in your arguments is correct, I have also had issues with that.
The application should now be configured for Launch in Eclipse using this run configuration. My verified environment is:
Eclipse Luna (v4.4)
Google Plugin for Eclipse (v3.8)
GWT Maven Plugin (v2.7.0)

Compilation unit is not on the build path of a Java project

I joined an SVN server and checked out the source files a project from that server. In the Eclipse editors, when I hit Ctrl + Space, I got the following error message:
This compilation unit is not on the build path of a Java project
What should I do to solve this problem?
Read this guide on how to use maven projects with eclipse
http://maven.apache.org/guides/mini/guide-ide-eclipse.html
Taken from the above link :
Reason why you get that notice :
Eclipse needs to know the path to the local maven repository. Therefore the classpath variable M2_REPO has to be set.
Solution
Execute the following command:
mvn -Declipse.workspace=<path-to-eclipse-workspace> eclipse:add-maven-repo
Restart your Eclipse IDE (if you already have it open) for this change to take effect.
You can also define a new classpath variable inside eclipse: From the menu bar, select Window > Preferences. Select the Java > Build Path > Classpath Variables page
For Simple Projects :
If you have a simple java project which is made up of only one module, using eclipse is very simple. To generate the eclipse project files from your POM you execute the following command:
mvn eclipse:eclipse
If you have created or checked out the project with eclipse, you only have to refresh the project in your workspace. Otherwise you have to import the project into your eclipse workspace (From the menu bar, select File >Import >Existing Projects into Workspace). In the latter case the project (directory) should not be located in your workspace, because eclipse might come into trouble, especially if you want to use eclipse as the scm client.
For a more detailed explanation refer the above link.
Import project as maven project.
File-> import-> Maven-> Exiting Maven Project-> Next-> Root Directory-> Browse your project from Disk
Follow these steps:
Right click project in Eclipse. Select to Run As → Maven build...
In Goals add eclipse:eclipse
Select Run
Wait for build to finish
Right click project in Eclipse. Select Refresh
This is due to the issue in build path .
If you had imported the project as Existing Maven project, do the following to resolve the issue.
Right click in the Package Explorer -> Maven -> Update project.
Or select the project in package explorer and perform Alt+F5 which is the shortcut for the maven project update.
Execute mvn eclipse:eclipse on command line and once the build is successful, refresh your project in eclipse. This resolve the issue.

Converting SVN project to maven project in Eclipse

I have downloaded a project (Maven based structure) from our SVN repository using Eclipse SVN plugin. Initially, Eclipse wasn't recognizing it as java project so I had to follow the following steps:
http://www.javaexperience.com/how-to-convert-svn-project-to-regular-eclipse-java-project/
The above steps worked well and the project was converted to java project.
Next I right clicked on the project and selected maven->Convert to maven project. Eclipse downloaded some jars and added it to the class path but not all files seem to have been downloaded successfully as I see Junit jar file missing error (where as junit is mentioned in pom.xml)
When I right click on the pom.xml file, I don't see the option "mvn install" or "mvn clean". I am using Eclipse Kepler which comes with maven plugin out of the box.
You will find the Maven commands in 'Run As', not in 'Maven'
I would first create a maven project using create maven project menu then add the SVN based source code to it.

Categories

Resources