Getting JUL to log via log4j2 while using Maven in JUnit tests - java

I'm running a little test project where I want my JUL logs to be redirected and appear as log4j2 logs.
I'm using the following Maven dependencies:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.0-M1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.14.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jul</artifactId>
<version>2.13.3</version>
</dependency>
To use the log4j-jul adapter, I'm supposed to set the system property java.util.logging.manager to org.apache.logging.log4j.jul.LogManager.
When I do that in my project's main method with
System.setProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager");
then logging works as desired. But if I use a JUnit test (run with mvn test) that does the same, like
#Test
public void loggingJULTest() {
System.setProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager");
java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger(MainTest.class.getName());
julLogger.info("Info Message from JUL");
julLogger.severe("Severe message from JUL");
julLogger.fine("Fine message from JUL");
}
then the logs appear in JUL style instead.
I tried to add the following configuration to Maven's Surefire Plugin in the pom.xml
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.apache.logging.log4j.jul.LogManager</java.util.logging.manager>
<buildDirectory>${project.build.directory}</buildDirectory>
</systemPropertyVariables>
</configuration>
but then the test gives no output and shows a warning
[WARNING] Corrupted STDOUT by directly writing to native stream in forked JVM 1. See FAQ web page and the dump file[..]
I'm confused about about what I'm supposed to be doing here.

If you are using version 3.0.0-M5 of the maven-surefire-plugin, you need to add <forkNode implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory"/> to the configuration.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<forkNode implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory"/>
...
</configuration>
</plugin>
</plugins>
</build>
Details: According to the Jira issue SUREFIRE-1614
P.S.: In the future for similar questions, please add version information for Java and Maven.

Related

How to build standalone executable cucumber jar file?

I want to create a executable jar file so anyone can run it from their computer with least install require components.
I found several tutorial but none of them a work.
When I execute jar file I've built they are return error like:
Error: Could not find or load main class fully.qualified.MainClass
Caused by: java.lang.ClassNotFoundException: fully.qualified.MainClass
OR like this:
Error: Could not find or load main class io.cucumber.core.cli.Main
Caused by: java.lang.ClassNotFoundException: io.cucumber.core.cli.Main
My project run from Intellij with no problem.
Here my project structure
https://i.stack.imgur.com/NcQzf.png
And my pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>CucumberSelenium</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cucumber.version>7.6.0</cucumber.version>
<selenium.version>4.8.0</selenium.version>
<webdrivermanager.version>5.2.1</webdrivermanager.version>
<junit.jupiter.version>5.9.0</junit.jupiter.version>
<apache.common.version>2.4</apache.common.version>
<projectlombok.version>1.18.24</projectlombok.version>
<maven.compiler.plugin.version>3.10.1</maven.compiler.plugin.version>
<maven.surefire.plugin.version>3.0.0-M7</maven.surefire.plugin.version>
<maven.compiler.source>19</maven.compiler.source>
<maven.compiler.target>19</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-bom</artifactId>
<version>${cucumber.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>${junit.jupiter.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit-platform-engine</artifactId>
<scope>test</scope>
</dependency>
<!-- JUnit Platform -->
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<!-- Selenium -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<!-- Web Driver Manager -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>${webdrivermanager.version}</version>
</dependency>
<!-- Apache Common -->
<dependency>
<groupId>org.apache.directory.studio</groupId>
<artifactId>org.apache.commons.io</artifactId>
<version>${apache.common.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${projectlombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>19</source>
<target>19</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<properties>
<configurationParameters>
cucumber.junit-platform.naming-strategy=long
</configurationParameters>
</properties>
<debugForkedProcess>true</debugForkedProcess>
<forkCount>0</forkCount>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<archive>
<manifest>
<mainClass>io.cucumber.core.cli.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I've run mvn clean compile assembly:single, it's output a CucumberSelenium-1.0-SNAPSHOT-jar-with-dependencies.jar file, but it wont runs.
I just came across a similar issue and, despite trying the ubiquitous
java -cp . org.example.Main
(while on current directory being where the Main.class is), I kept getting this dreaded
"Error: Could not find or load main class"
I eventually resorted to comparing the actual command with parameters invoked by IntelliJ (on IntelliJ IDEA's debug log) with mine, and discovered that the following solves the issue:
java -cp C:\Users\WebViwer\IdeaProjects\MyProj\target\classes org.example.Main
I am guessing that once the fully qualified class name is specified, the current directory (where the class resides) is no longer valid as a classpath: Only the top level classes directory should be specified (in this org.example, 2 levels up).
You have a a few problems going on.
The maven-assembly-plugin should not be a in the dependencies section. It is not a dependency used by the runtime code of your project.
Your step definitions, feature files and glue code located in src/test are not included in the jar file build by the assembly plugin.
Your test scoped dependencies will also not be included by the assembly plugin either.
You must configure the containerDescriptorHandler of the assembly plugin with metaInf-services or the plugin will not merge files in META-INF/services correctly.
You can verify most of these by opening the generated jar file (it's a .zip file in disguise).
My project run from Intellij with no problem.
When running tests in Intelij you are using the test scope, the jar file only includes runtime scoped code.
For a more comparable test you must create a new run configuration that invokes the main method.
I found several tutorial but none of them a work.
It appears that you are relatively new to Java and Maven. It would be prudent to follow a proper course first rather than tutorials. You are missing fundamental knowledge that is generally not taught in tutorials.
I want to create a executable jar file so anyone can run it from their computer with least install require components.
It's also prudent to consider why you are doing this.
Tests will typically change as quickly as the source code they are testing does. Manually distribution of jar files won't keep up with this.
This means it's generally better to integrate the tests and the test source code into the automated build pipeline of the project they test.
This also means that you don't need to distribute your tests as a jar. Rather you should expect (and possibly train) people to use Maven, GIT and Java.

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile)

I know this is a duplicate question but the answers on other topics didn't help me.
I'm using Eclipse Photon, Java Version :10, I've set jdk/jre versions on 10 in eclipse and pom.xml file. I've changed eclipse.ini file :
-Dosgi.requiredJavaVersion=10 (it was set to 1.8)
and also I've added plugin in my pom.xml :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>10</source>
<target>10</target>
</configuration>
</plugin>
Nothing helped. This is my pom.xml :
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.luv2code</groupId>
<artifactId>spring-security-demo-06-user-roles</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<name>spring-security-demo</name>
<properties>
<maven.compiler.source>10</maven.compiler.source>
<maven.compiler.target>10</maven.compiler.target>
</properties>
<dependencies>
<!-- Spring Security -->
<!-- Spring Security WEB -->
<!-- Spring Security taglibs -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>5.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>5.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>5.1.1.RELEASE</version>
</dependency>
<!-- Spring MVC support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.2.RELEASE</version>
</dependency>
<!-- Servlet, JSP and JSTL support -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- TO DO: Add support for Maven WAR Plugin -->
<build>
<finalName>spring-security-demo</finalName>
<pluginManagement>
<plugins>
<plugin>
<!-- Add Maven coordinates forL maven-war-plugin -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>10</source>
<target>10</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
The dependencies aren't being read in class files and also I've tried deleting .m2 repository and starting Eclipse and doing the : Maven->Clean, Maven->install, and than Maven->update project. Nothing helped. I'm really stuck here for about 2-3 hours now.
Note: in Windows->Preferences->installed JRE's the jre10 was marked with the tick. I changed it to mark the jdk10. but still error :
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project spring-security-demo-06-user-roles: Compilation failure
Everything was working fine until I added the dependency of : spring-security-taglibs.
Deleting the dependency doesn't do anything aswell.
Check properly settings with version of your project in eclipse and version of your runner for maven.
I have reproduced the same issue with maven-compiler plugin, but using version 3.8.1:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project testName: Fatal error compiling
My POM was:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
To clarify:
in project I'm using Java 11 and IntelijIDEA (but logic I think the same for eclipse). So I'm using maven lifecycle phases fine only if my version of project (check properly Project Structure -> Project Settings) corresponds to version of maven runner.
E.g. if version of runner is for java 8, but project settings are for Java 11 then I'm getting this error. If I have the same for both then I don't have any problems.
And I highly recommend to check all settings for maven and the whole project. It helps to avoid the issues in the future. Deleting folder for maven is as alternative solution, but it must be last thing that you need to do.
It started working Automagically . FIX : delete .m2 repository.
I did that yesterday but it didn't help, today somehow, deleting the .m2 repository and updating the project helped !
Confirm, delete your entire local repository pointed to by .m2/settings.xml, usually this is .m2/repository
I updated my Java SDK to 11.9 and reloaded the project. With this I solved my problem.
I had the same issue, it was because the Spring Boot project was using Java 11 but my %JAVA_HOME% variable was pointing to Java 8 home directory. I resolved the issue by changing the path to %JAVA_HOME% variable.
You just need to go to preference(eclipse in this case) and change the right version of JDK like below in pic:

Cannot create Launcher without at least one TestEngine; consider adding an engine implementation JAR to the classpath in Junit 5

I got following execption when i tried to run test case in junit5:
Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19:test (default-test) on project CRUD-App: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.19:test failed: There was an error in the forked process
org.junit.platform.commons.util.PreconditionViolationException: Cannot create Launcher without at least one TestEngine; consider adding an engine implementation JAR to the classpath
at org.junit.platform.commons.util.Preconditions.condition(Preconditions.java:161)
at org.junit.platform.launcher.core.DefaultLauncher.<init>(DefaultLauncher.java:52)
at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:42)
at org.junit.platform.surefire.provider.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:59)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:286)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:240)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)
pom.xml
<dependencies>
...
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit5-api</artifactId>
<version>5.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.0-M2</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Test Class:
public class PersonServiceTest {
final Database database = Database.from("jdbc:h2:mem:" + App.DB_NAME);
final PersonService personService = new PersonService(database);
public PersonServiceTest() {
}
#Test
#DisplayName("#Person#insert()")
public void testInsert() {
personService.insert(new PersonBuilder()
.setId(1).setName("Bhuwan")
.setAddress("KTM")
.setContactNo("984849").createPerson()
);
}
}
Maven Goal: mvn test
Mixing ALPHA snapshot artifacts (i.e., org.junit:junit5-api:5.0.0-SNAPSHOT) with M2 artifacts (i.e., org.junit.platform:junit-platform-surefire-provider:1.0.0-M2), won't work.
The Maven section in the user guide suggests to check out the pom.xml from the junit5-maven-consumer project. If you follow that example, you will end up with something like the following.
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<junit.jupiter.version>5.0.0-M2</junit.jupiter.version>
<junit.platform.version>1.0.0-M2</junit.platform.version>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
To write your tests, you only need the junit-jupiter-api; however, in order to run your tests you must have a TestEngine on the classpath. For JUnit Jupiter you therefore need junit-jupiter-engine on the classpath as well.
As Nicolai Parlog pointed out, you could add junit-jupiter-engine as a dependency for the maven-surefire-plugin; however, that would not include the JupiterTestEngine in the classpath for your IDE.
If you're only running tests via Maven or with a recent beta version of IntelliJ 2016 (which has built-in support for JUnit 5), then you may not care if JupiterTestEngine is on the classpath in your IDE. But... if you're using Eclipse, NetBeans, or a non-beta version of IntelliJ, you'll definitely want the JupiterTestEngine on the classpath in the IDE as well.
Regards,
Sam (core JUnit 5 committer)
Ended up here since getting the same error using Gradle and JUnit 4. The solution in this case can be found in the docs:
The JUnit Platform can run JUnit 4 based tests as long as you
configure a testImplementation dependency on JUnit 4 and a
testRuntimeOnly dependency on the JUnit Vintage TestEngine
implementation similar to the following.
A test engine is also needed:
dependencies {
testImplementation("junit:junit:4.13.2")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.8.2")
}
The Maven Surefire plugin not only needs the JUnit 5 provider but also a TestEngine implementation to run tests with. To quote the JUnit 5 docs:
In order to have Maven Surefire run any tests at all, a TestEngine
implementation must be added to the runtime classpath.
In accordance with that the following works:
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.0-M4</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.0.0-M4</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.0.0-M4</version>
<scope>test</scope>
</dependency>
</dependencies>
Note that this configuration makes the engine a dependency of the surefire plugin, not of your test code.
simply adding below dependency solved this prob.
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
I solve it changing
classpath "org.springframework.boot:spring-boot-gradle-plugin:2.1.8.RELEASE"
to
classpath "org.springframework.boot:spring-boot-gradle-plugin:2.2.0.RELEASE"

HotSwaping code into "mvnDebug tomcat:run"

Usually i start tomcat using mvnDebug tomcat:run.
After Code-change i need to use mvn tomcat:redeploy.
This is sub-optimal because i often only change content of existing method-bodys.
Can I HotSwap the method's body into the runtime, and hot-redeploy as a fallback?
I have unfortunatally nothing found like a maven-hotswap-plugin.
faces-config.xml
... <application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
<locale-config>
<default-locale>de_DE</default-locale>
</locale-config>
<resource-bundle>
<base-name>Message</base-name>
<var>message</var>
</resource-bundle>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
</faces-config>
web.xml:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
pom.xml:
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-envers</artifactId>
<version>4.3.0.Final</version>
</dependency>
<dependency>
<groupId>net.java.dev.ajax4jsf</groupId>
<artifactId>ajax4jsf</artifactId>
<version>1.0.6</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.6.Final</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-api</artifactId>
<version>1.2.10</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-impl</artifactId>
<version>1.2.10</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.myfaces.tomahawk</groupId>
<artifactId>tomahawk12</artifactId>
<version>1.1.9</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.sun.facelets</groupId>
<artifactId>jsf-facelets</artifactId>
<version>1.1.14</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>3.1.0.GA</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.2-1004-jdbc41</version>
</dependency>
<dependency>
<groupId>servletapi</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<contextReloadable>true</contextReloadable>
</configuration>
</plugin>
</plugins>
</build>
You can use Jrebel - it works exactly as you expect. You just need to specify javaagent and it will reload all classes and framework changes during runtime. It also works with remote servers
To integrate it with maven project you have to add jrebel-maven-plugin, which will generate all configuration (rebel.xml) files.
Without JRebel you can use standard HotSwap mechanism but it only allows to reload method bodies
One of the best solutions for your situation is JRebel
What you need to do is make the appropriate changes to the framework
and integrate it using a jrebel-maven-plugin.
It allows to reload all the method bodies.
Once you are done with the link-up a auto xml configuration file will be generated which will be used as a config file for the plugin.
Mention Your Java Agent as well.
After the successful test you can also integrate it with a build
JRebel is a good option. It isn't cheap but there are open source licences available. The installation instructions for Maven are here:
http://zeroturnaround.com/software/jrebel/learn/maven/
We get this working through a specific run profile and embedded Tomcat. This is a specific sub-module that depends on the other projects that build the web application wars. So if you configure something like the following in the runner submodule:
<profiles>
<profile>
<id>run</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<executions>
<execution>
<id>run-wars</id>
<goals>
<goal>run-war-only</goal>
</goals>
<phase>integration-test</phase>
</execution>
</executions>
<configuration>
<warDirectory>theWar</warDirectory>
<path>/relativepath</path>
<systemProperties>
<webapps>
<webapp>
<groupId>${project.groupId}</groupId>
<artifactId>myArtifact</artifactId>
<version>${project.version}</version>
<type>war</type>
<asWebapp>true</asWebapp>
<contextPath>myContext</contextPath>
</webapp>
</webapps>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
You can run this with mvn package -Prun which you should be able to shut down with Ctrl+C.
Then, whilst this is running in one terminal, make your code changes, open a new terminal and run mvn compile. With JRebel going the changes should be reflected virtually instantly in your web app.
There should be nothing preventing you from running these same goals through Eclipse's m2e plugin.
It seems that you may be using some old version of the maven tomcat plug-in, because newer versions should be referred as tomcat6 or tomcat7, e..g. mvnDebug tomcat7:run. I'm on 2.2 and hot swap from Eclipse works just fine.
To clarify a little more, that's what I see in the command prompt when starting the app with mvn tomcat:run:
...
[INFO] >>> tomcat-maven-plugin:1.1:run (default-cli) # tomcatMvnDebug >>>
...
Notice the 1.1.
And that's what I see when starting the app with mvn tomcat7:run:
...
[INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) # tomcatMvnDebug >>>
...
Notice that this time maven uses tomcat plug-in version 2.2.
I'd use the HotSwap functions of Eclipse or IntelliJ. They both work very well for me: Just run maven goal in debug mode (tomcat:run).
We generally develop the web applications using grails which already has reload feature, I believe it's done with the spring-loaded plugin. It may be a replacement to jRebel (although I'm not sure if it will work for you, but if you want to save a few hundreds $$, may be worth trying).
So, basically I see the following options:
Use the framework which already supports reloading classes (Grails, Play)
Use some javaagent like spring-loaded or JRebel
Use some javaagent integrated into the IDE (I use IntelliJ IDEA and highly recommend it. Not sure if it works in the free community edition though).
https://github.com/spring-projects/spring-loaded
There is a maven plugin. It doesn't seem to be maintained. However from short look at the source code I believe you can make it work.
It is based on similar plugin for ant, so alternatively you can use maven antrun to execute this
Nevertheless it is going to have the same capabilities (and limitations) as hotswap in any IDE.

maven-jaxb1-plugin error while executing in jdk1.6 and maven 3.0.3

I am running a maven script which uses maven-jaxb1-plugin version 1.0.rc-11 to generate the jaxb classes from xsd. The script was running successfully in the java version 1.4 and maven version less than 3 . Now the same script when run in java version 1.6 and maven version 3.0.3 environment throws an exception **
A required class was missing while executing
org.jvnet.jaxb1.maven2:maven-jaxb1-plugin:1.0.rc-11:generate:com.sun.msv.grammar.Grammar
**
All the dependencies for this plugin are available in my repository.Still I am getting this error.
Below is my pom.xml
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>1.0.6</version>
</dependency>
<dependency>
<groupId>javax.xml.parsers</groupId>
<artifactId>jaxp-api</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb1.maven2</groupId>
<artifactId>maven-jaxb1-plugin</artifactId>
<version>1.0.rc-11</version>
<executions>
<execution>
<configuration>
<schemaIncludes>
<include>response.xsd</include>
</schemaIncludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Is it like maven-jaxb1-plugin can not be used in jdk1.6 and maven 3.0.3 environment.Any help is much appreciated,Thanks.
The class that it says it is missing, com.sun.msv.grammar.Grammar, is present in jaxb1-impl.jar according to findjar.com:
http://www.findjar.com/class/com/sun/msv/grammar/Grammar.html
That class does not seem to be present in jaxb-impl.jar:
http://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl/1.0.6
It does seem to be present in jaxb1-impl.jar:
http://mvnrepository.com/artifact/com.sun.xml.bind/jaxb1-impl/2.0
So maybe change your dependency to:
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb1-impl</artifactId>
<version>2.0</version>
</dependency>

Categories