Debuggin Vert.x-Maven-Projekt inside Eclipse - eclipse

I am currently developing an Vert.x Application inside Eclipse with maven. I did the Projekt-Setup like descripted here: http://vertx.io/maven_dev.html
Everything went fine, the project builds succesfully and the server gets started successfully in debug mode via the maven launch configuration with the goal: package vertx:runMod
However, if i set a breakpoint, the debugger stops at the right position and showing me the right stacktrace but it doesnt show me the line inside the source. instead of that it shows the infamous "Source not found"-screen with the "Edit Source Lookup Path"-Button.
The funny thing about this is that this also happens when the breakpoint is inside one of my own java files.
I can also navigate into the source of for example vertx-core-2.0.0-final-sources.jar via STRG-Left click on a vert.x class . After doing this i can see the debug-Infos on Variables ect. via mouse-over as usual. If i double click on the stack again eclipse changes back to the "source not found"-screen-tab again.
I also tried to run the maven goal "clean eclipse:eclipse" on my Project as suggested here: Run Vertx in an IDE with no success.
I also tried all suggestions from here: Eclipse Maven debug - source not found with no success
I think it has something to do with the way the application gets launched. (via vert.x Container-Instance out of maven goal)
Its Eclipse Luna (4.4) with m2e-Plugin vers. 1.5 with maven 3.2.1, and vert.x 2.1
Any Help would be great. THX in advance

At least i found out how to debug into my own source files. I simply had to generate the source.jar for my project when it gets installed via the maven goal. I added the following to my pom under the <plugins> -section
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
After that i linked this generated source-jar-file to my debugger via the "Edit Source Lookup Path"-Button (this has to be done only the first time)
The flaw about this is, if i change a single line in my source files i have to rebuild the whole projekt including the source.jar via maven -install. If i am not doing this the debugger ends up in wrong line numbers.
I also didnt found out how to debug into the classes that are inside my dependency-jars. So at least this isnt solved yet.

Related

Launch GWT in dev mode while running server on Spring-boot

I have created web application using Spring boot and gwt 2.6.0.
Changed location of generated files:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${gwt.plugin.version}</version>
<executions>
<execution>
<configuration>
<module>my.module</module>
<webappDirectory>src/main/resources/gwt-public/</webappDirectory>
</configuration>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
And if running my application standalone everything works correctly, because all the needed files are accessible.
But the question is - how to run GWT in development mode (from Intellij IDEA). I am trying to run it in -noserver mode, it launches but in browser there is nothing.
As I understand I need to specify war directory which is used by dev plugin, so it means I need to explicitly set packaging to war? I have no clear thoughts about it.
you can compile a war, run the server and then run gwt debug, but after the browser opens change the url to the localhost:xxxx whatever spring is running, but leave the servercode=127.0.0.1 as is.
or you can use gwt:debug on maven plugin instaed of compile.
looky here: http://mojo.codehaus.org/gwt-maven-plugin/debug-mojo.html
I got this working by adding this to your gwt-maven-plugin configuration:
<superDevMode>false</superDevMode>
If you are going to change the URL as Zerkotin suggests, then I supplied this additional property:
<noServer>true</noServer>
to stop the mvn-gwt-plugin from starting up the embedded Jetty instance. But this did not allow me to recompile on the fly.
To get it working in super dev mode, I set this up in my gwt-maven-plugin config:
true
true
Then I started up Spring Boot as normal (using java -jar myweb.jar). Then I started up maven gwt plugin (mvn gwt-debug), attached IntelliJ to the debugger (using remote), went to code server URL (NOT my app URL), set up those book marklets, then went to my app URL, and when I want to recompile, I just hit those bookmarklets.

wro4j & m2e Eclipse not compiling LESS

I am trying to setup my developer env so that I can use maven to compile my LESS files for formal builds, but also have Eclipse compile the LESS for incremental builds so I dont have to keep kicking of maven tasks every time I make a LESS change. Having looked around - it seems like wro4j & the maven plugin & the m2e-wtp plugin should provide all that.
My setup is as follows: I have just installed the latest stable Eclipse (Java EE package, that includes the WTP stuff - v4.3) and I have installed the m2e plugin and the m2e-wtp plugins.
pom.xml:
<plugin>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-maven-plugin</artifactId>
<version>1.4.5</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<targetGroups>roa-all</targetGroups>
<destinationFolder>${project.build.directory}/${project.build.finalName}</destinationFolder>
<cssDestinationFolder>${project.build.directory}/${project.build.finalName}/css/</cssDestinationFolder>
<jsDestinationFolder>${project.build.directory}/${project.build.finalName}/js/</jsDestinationFolder>
<wroManagerFactory>ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory</wroManagerFactory>
</configuration>
</plugin>
wro.properties:
preProcessors=cssImport,semicolonAppender
postProcessors=lessCss,cssMinJawr
wro.xml:
<groups xmlns="http://www.isdc.ro/wro">
<group name="roa-all">
<css>/less/*.less</css>
</group>
</groups>
Inside my /less/ folder are basically a few css files that I have renamed .less files, and one where I have actually added some LESS syntax with a few colour variables set. This mostly works, as I make changes to my LESS, the plugin detects and rebuilds my uber css file, however, rather critically, it doesn't seem to be compiling the LESS - it combines the files, and minifies, but my #variables are all still in LESS syntax.
I also noticed that the maven plugin was up to v 1.7.0 so tried upgrading to that to see if that was the problem, but that just does nothing at all (nothing gets built at all and I have no uber css etc)
Anyone had any experience setting this up or know anything I have missed in the setup?
The problem was because I had some invalid LESS in one of my files - this basically meant the compile step was failing, so the other LESS files were not being compiled to CSS (which resulted in the LESS variables being output in my file) - With the Eclipse incremental build, this failure was not being reported so I didn't see it.
I discovered it by explicitly running the maven command, and then got the normal maven logs which included details of the compilation failure.
That aside, the eclipse incremental build for LESS is working really nicely since!
As mentioned in the comments above, I wrote up how to set it all up here:
Eclipse & LESS - Better development time with incremental builds

Run JET Templates without Eclipse

I need to generate java code from jet templates using a maven project and it should be done outside eclipse environment, but so far i haven't figure out how to do this.
I'm using maven 3x and jet 1.1.x.
I've tried several approaches but none of them seems to work:
invoke library org.eclipse.emf.codegen.jet.JETCompiler. This library seems to have a strong dependency with eclipse's environment and for such reason it failed.
one of maven's jet plugin doesn't work neither and i'm using the same example as provided in the offical website ([tikal-maven-jet-plugin][1]), here's how it looks like:
http://network.tikalk.com/release/tikal-maven-jet-plugin/usage.html
Does anyone have an idea how to do this?
Thanks a lot,
Carlos
Because of the way JET works, it'll only actually be runnable inside an eclipse environment. However, it's actually possible to launch eclipse headlessly to run an ant build script, so you get the eclipse parts you need running, without the UI. In order to do this, you need to launch the org.eclipse.ant.core.antRunner application. There's some documentation on how to do that here: http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Ftasks%2FantRunner.htm
Once you've launched the antRunner application, you can use the JET ant tasks to compile your templates and run your transform: http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.jet.doc%2Freferences%2Fant%2FantTasks.xhtml
There are some important caveats about headless template compilation which are relevant if you're headlessly compiling eclipse plugins, documented here: http://wiki.eclipse.org/JET_FAQ_How_to_I_compile_JET_templates_in_a_headless_build
I'm not sure how well any of this integrated with Maven, but this seems to be the best approach from ant. If you're wanting to run a transform from Java, there's some information here: http://wiki.eclipse.org/JET_FAQ_How_do_I_run_a_JET_transformation_from_Java%3F. You will still need to be in an eclipse environment for it to work though.
The tikal-maven-jet-plugin worked for me.
Here's a sample of a JET file I used in src/main/templates/generator.jet, I don't use the EMF classes, just standard Map.
<%# jet class="TableModelGenerator" package="net.trajano.framework.tool" %>
<% java.util.Map meta = (java.util.Map)argument; %>
package <%=meta.get("PackageName")%>;
public class <%=meta.get("ClassName")%> {
}
The plugin configuration I used is
<plugin>
<groupId>com.tikal</groupId>
<artifactId>tikal-maven-jet-plugin</artifactId>
<version>0.4.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<includeTemplates>
<include>**/*.jet</include>
</includeTemplates>
</configuration>
</plugin>

Eclipse/Maven: JUnit tests not compiled when running them

I am working on a project using Maven and Eclipse (m2eclipse plugin). I've got problems with the JUnit tests:
Sometimes, when running them within Eclipse, they wont be compiled, but the old class files are used instead. When I delete the class files, I get ClassNotFoundExceptions in Eclipse. I then have to manually recompile them by using mvn test-compile or other goals.
I also noticed that the class files of the tests sometimes are put into the classes subdirectory instead of test-classes.
I really can't figure out what is wrong.
The JUnit java files are within src/main/java and are correctly named (*Test.java).
Do I have to compile and run them always via Maven? Why doesn't Eclipse compile the files when I want to run them? (Interestingly, sometimes it does. Sometimes everything works perfectly.)
I had the same problem with STS Eclipse (Spring development variant), m2e and JUnit. The solution was to set the output folder for src/test/java to target/test-classes:
Right click the src/test/java folder in the Package Explorer
Select Build Path -> Configure Output Folder
Enter target/test-classes, click OK
Now the changes in test classes are compiled correctly and you should be able to run JUnit tests in Eclipse.
The problem is that Eclipse compiles the unit tests to the default output folder target/classes while JUnit plugin correctly tries to run them from test-classes.
There are a few duplicates to this question:
ClassNotFoundException when running JUnit unit tests within Eclipse (using Maven)
Eclipse doesn't see my new junit test
junit not using the newest file
In addition to the answer below
Right click the src/test/java folder
Select Build Path -> Configure Output Folder
Enter target/test-classes, click OK
you should check to ensure that your builder is setup correctly by right clicking your project and going to Properties -> Builder. If you see that your builder is missing, you need to install one. In my case, the maven project had an AspectJ dependency and when I used the Maven Eclipse plugin to build my Eclipse project, it was looking for an AspectJ builder by default. I installed the AspectJ development tools and it solved the problem.
Hope this helps!
The most likely explanations for the problem you are facing is that the output folder of src/test/java is not correctly configured.
Instead of fixing this configuration manually, you can have m2eclipse fix this for you: Just right-click on the project and choose Maven > Update Project.
And another point: JUnit test classes should be in src/test/java, not src/main/java, otherwise they aren't detected correctly by Maven as test classes and they would be included in the packaged jar and not in the test jar.
I faced same issue. Tried above suggestions of configuring output folder & Maven>Update Project but neither worked. Finally changed my testOutputDirectory to "build/classes" as well and now Unit Tests are getting picked up and executed.
Finally found the reason for the issue. In my pom we had also configured maven compiler plugin as below
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<outputDirectory>build/classes</outputDirectory>
</configuration>
</plugin>
outputDirectory configuration is not needed and was the cause of above issue. After removing this tag, junits are getting compiled to build>testclasses folder and are being run during maven build as well. Yippee :)
Please check "testSourceDirectory" path which can be configured in your
pom.xml. And then, Add the folder (configured in "testSourceDirectory" path) to the eclipse build path.
Please find the sample "testSourceDirectory" in pom.xml below:
<build>
<testSourceDirectory>src/test/java</testSourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
Make sure that is there any exclamation mark on your project icon! In my case, i ignored that there is a exclamation point like:
exclamation point on project icon
Open the "Markers" perspective, then troubleshoot the problems according to the tips.
what the "Markers" perspective show
The junit test classes can be execute successfully after i called "mvn clean test" because they are not refer the unreadable jar which be warned in "Markers" perspective.Therefor, it's easily to ignore it..
For someone working on java-scala mix project, this is something to note.
Even after doing the configuration in the manner shown below,
<build>
<testOutputDirectory>${basedir}/target/test-classes</testOutputDirectory>
<plugins>
...
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.3.2</version>
<configuration>
<testSourceDir>${basedir}/src/test/scala</testSourceDir>
<testOutputDir>${basedir}/target/test-classes</testOutputDir>
</configuration>
</plugin>
</plugins>
</build>
and doing a Maven > Update Project, eclipse honours the output directory of the src/test/java folder in the project, however, not for the src/test/scala folder. (You can figure this out by right-clicking on the specific source folder and choosing Build Path > Configure Output Folder... which should display the location as specified in the pom for the former case, however, not for the later case.
This is already a known bug for using scala with m2e as mentioned here: http://scala-ide.org/docs/tutorials/m2eclipse/
Warning
As of March 2013, a bug causes both src/main/scala and src/test/scala to use the default output folder (target/classes). This may be confusing >when building tests, since their class files will not end in target/test-classes, as they would when building on the command line. You can work around this by manually changing the output folder for src/test/scala.
Eclipse is not expecting anything else to be mucking with the class files. It assumes that if you haven't editted the file in eclipse it hasn't changed and doesn't need compiling. I think the issue stems from eclipse and maven sharing an output directory. I've often seen this if my mvn build fails, it will have deleted the class files as part of the clean but not compiled new ones. I think the best solution would be to have seperate build dirs for mvn and eclipse, but I've never look into this.
My problem wasn't the JUnit plugin but rather the configuration in my pom.xml.
After reviewing all the answers to this question, #Gulats's answer implied to me that I should try setting a testOutputDirectory in my maven-compiler-plugin section, and that did the trick:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<testOutputDir>${basedir}/target/test-classes</testOutputDir>
</configuration>
</plugin>

Problems by import of a multiple modules maven 2 project into eclipse workspace

I was wondering if someone has experienced the same problem as me and can help me.
I have a maven project which contains 6 modules. Some of modules are depending on each other. The project is written in Java and builds to jars, wars and aar. I've been trying to import it to Eclipse with the m2eclipse plug-in. It seems to work fine until the project builds. During the build process I get hundreds of errors complaining about missing Java files which are generated. As I found out eclipse can't recognize that some of generated packages should be interpreted as source code. I don't realy know what to do with it as I spent a lot of time already trying to solve this issue. The project is building fine with command line. My target is to debug the whole project on Tomcat server that's why I want to use eclipse as it has a pretty good integration with Tomcat.
Every help would be greatly appreciated.
Thank you!
As documented in the Why generated source folders are not added to classpath entry of the FAQ:
Maven plugins used to generate source
code from resources or other sources
can register additional source folders
to Maven project during the build.
Usually such plugins are bound to
process-resources (or
process-test-resources) build phase
(for example jaxb, modello or xdoclet
plugins). This means that to get those
source folders for generated sources,
we have to run corresponding Maven
build phase.
Not all projects using generated
sources, so for performance reasons,
m2eclipse does not run any Maven goals
by default on project import. This can
be changed in the Maven settings in
"Window > Preferences... > Maven >
Goals to run on project import" (e.g.
you can specify "process-resources"
build phase or specific plugins in
that field).
Alternatively you can run "Maven >
Update project configuration" action
from the project popup menu, which is
configured to run "process-resources"
by default and it can be also changed
on the same preference page.
So either add the goal to which the source generation process is bound to the list of goals to run on import or generate sources by running maven and update the project configuration.
Try using mvn eclipse:eclipse
Under the project where you have additionally generated source. When this is generated by maven it is normally under target folder.
Therefor eclipse:eclipse will recognize this and add as a source folder.
Rembember to refresh the project after this.
Use build-helper-maven-plugin (sample bellow) to tell Eclipse to add a generated folder to the build path :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/cxf</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
Add this in the pom of each project that generates sources...