I have a GWT project that I currently compile using Eclipse GWT plugin, but now I would like to make my project compilable independently from the IDE, and the approach is to use Maven only.
From my research I found out that you need to add the GWT Compiler plugin to the pom.xml in order to compile the code from Java to Javascript files (the JS files can be later packaged inside a war), but I can't seem to find the compiler dependency in maven repository nor a good documentation of the compiler. Can you post a "basic" working pom.xml file that can be used to compile a Hello world GWT project, that would be very appreciated, Thank you.
EDIT:
I'm using GWT 2.7.0
You can use the gwt-maven-plugin. You have mentioned you have the Eclipse GWT plugin already, so you can create a new GWT project (e.g. right click on the Project Explorer -> New -> Other... -> GWT Web Application Project). Fill in the project name and package and make sure to enable the checkbox "Generate a Maven Project". Then you have a working sample of a 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/maven-v4_0_0.xsd">
<!-- POM file generated with GWT webAppCreator -->
<modelVersion>4.0.0</modelVersion>
<groupId>com.world.hello</groupId>
<artifactId>HelloWorld</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>com.world.hello.HelloWorld</name>
<properties>
<!-- Setting maven.compiler.source to something different to 1.8
needs that you configure the sourceLevel in gwt-maven-plugin since
GWT compiler 2.8 requires 1.8 (see gwt-maven-plugin block below) -->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<!-- Don't let your Mac use a crazy non-standard encoding -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencyManagement>
<dependencies>
<!-- ensure all GWT deps use the same version (unless overridden) -->
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt</artifactId>
<version>2.9.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<!-- Output classes directly into the webapp, so that IDEs and "mvn process-classes" update them in DevMode -->
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
<plugins>
<!-- GWT Maven Plugin-->
<plugin>
<groupId>net.ltgt.gwt.maven</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>1.0-rc-8</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<moduleName>com.world.hello.HelloWorld</moduleName>
<moduleShortName>HelloWorld</moduleShortName>
<failOnError>true</failOnError>
<!-- GWT compiler 2.8 requires 1.8, hence define sourceLevel here if you use
a different source language for java compilation -->
<sourceLevel>1.8</sourceLevel>
<!-- Compiler configuration -->
<compilerArgs>
<!-- Ask GWT to create the Story of Your Compile (SOYC) (gwt:compile) -->
<arg>-compileReport</arg>
<arg>-XcompilerMetrics</arg>
</compilerArgs>
<!-- DevMode configuration -->
<warDir>${project.build.directory}/${project.build.finalName}</warDir>
<classpathScope>compile+runtime</classpathScope>
<!-- URL(s) that should be opened by DevMode (gwt:devmode). -->
<startupUrls>
<startupUrl>HelloWorld.html</startupUrl>
</startupUrls>
</configuration>
</plugin>
<!-- Skip normal test execution, we use gwt:test instead -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
Running mvn clean install on the console will compile your project using Maven. Or you right click your project on the Project Explorer and select Maven -> Update Project...
Sometimes, after creating the GWT Maven Project, Eclipse doesn't automatically recognize it as a Maven Project. If that is the case, right click your project on the Project Explorer and select Configure -> Convert to Maven Project.
Related
I'm having issues with my Maven project. I am trying to use the command "mvn clean install" but I'm having no success. I have updated & cleaned the Maven project in the Eclipse IDE. I have also deleted the folder "repository" within the ".m2" directory. This creates the folder again but I keep getting the same error:
My pom.xml file:
<properties>
<version.thorntail>2.2.0.Final</version.thorntail>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>bom-all</artifactId>
<version>${version.thorntail}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<finalName>demo</finalName>
<plugins>
<plugin>
<groupId>io.thorntail</groupId>
<artifactId>thorntail-maven-plugin</artifactId>
<version>${version.thorntail}</version>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>jaxrs</artifactId>
</dependency>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>cdi</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.ogm</groupId>
<artifactId>hibernate-ogm-mongodb</artifactId>
<version>5.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.8.0</version>
</dependency>
</dependencies>
Any help would be greatly apreciated!
The problem is the Maven version (BTW which one are you using?)
When I run my Thorntail project using eclipse's embedded maven (version 3.5.3 ) it works.
When I run it using my local maven (version 3.6.0) I get the same error.
Solution: use a compatible version of maven. ( try 3.5.3 or 3.5.4) both work without issues with thorntail.
If you want to configure a different eclipse maven version go to:
Eclipse -> preferences -> Maven -> installations
there you can add a new one.
There's a problem due to third-party dependencies in Thorntail 2.x, that are incompatible with latest Maven release. The new Thorntail version should be the 2.3.0.Final once released.
On GitHub, you can track the status of the issue here
My first time using NetBeans with Maven. Everything works great from within NetBeans. Can build, package install, etc. Can debug and step through code. The problem starts when I attempt to debug my code by attaching to another application which links a JVM instance instead of debugging within NetBeans.
I am attaching to a process using shared memory transport and it succeeds. When I call from that process a java method with a breakpoint, it breaks. I can inspect variables and I can tell that it stopped in the right place, but it refuses to step through the code. NetBeans does not highlite in green the line where it stopped and stepping through the code leads netbeans into some Java bowels popping up Integer class, HashMap class, etc. and complaining that no source code is available. I can however set another breakpoint in my code and hit continue. It will stop there, but again will not step.
My speculation is that it has something to do with maven and incomplete debug information in my class files. If I reconfigure my project to use ant everything works correctly, but going back to maven screws it up again.
The Debugging view in NetBeans shows "Hidden Source Calls":
Anybody has any thoughts? Thanks
I am starting my application with linked jvm.dll with the following options:
-Xdebug -Xrunjdwp:transport=dt_shmem,address=myexecutable,server=y,suspend=n
Here are my sample pom files:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>com.some.company.edited</groupId>
<artifactId>atpg-parent</artifactId>
<version>0.1</version>
<packaging>pom</packaging>
<name>Parent Project</name>
<properties>
<!-- Build Metadata -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- App & Platform Versions -->
<java.target.version>1.7</java.target.version>
<junit.version>4.12</junit.version>
<!-- Build Plugin Versions -->
<maven.compiler.plugin>3.2</maven.compiler.plugin>
</properties>
<modules>
<module>atpg-main</module>
<module>atpg-dm</module>
</modules>
<!-- Dependency VERSIONS -->
<dependencyManagement>
<dependencies>
<!-- Test Dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<!-- Shared Dependencies -->
<dependencies>
<!-- Test Dependencies (can't hurt to include these all the time) -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<version>${maven.compiler.plugin}</version>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.target.version}</source>
<target>${java.target.version}</target>
<debug>true</debug>
<debuglevel>lines,vars,source</debuglevel>
</configuration>
</plugin>
</plugins>
</build>
http://maven.apache.org/maven-v4_0_0.xsd">
4.0.0
<parent>
<groupId>com.some.company.edited</groupId>
<artifactId>atpg-parent</artifactId>
<version>0.1</version>
</parent>
<artifactId>atpg-main</artifactId>
<packaging>jar</packaging>
<name>Main Project</name>
<dependencies>
<!-- Project module dependencies -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>atpg-dm</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
http://maven.apache.org/maven-v4_0_0.xsd">
4.0.0
<parent>
<groupId>com.some.company.edited</groupId>
<artifactId>atpg-parent</artifactId>
<version>0.1</version>
</parent>
<artifactId>atpg-dm</artifactId>
<packaging>jar</packaging>
<name>Exchange Format Data Model</name>
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<version>0.13.1</version>
<artifactId>maven-jaxb2-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Issue resolved. Resolution was extremely simple. Turns out that with Maven projects created outside of the NetBeans environment one has to open not only the parent project, but also all the modules in the project. Due to my ignorance, I did not do that. I only opened the parent project.
In the open project dialog there is actually a check box "Open Required Projects:" and it was off. Once I checked it, my parent opened with all modules as separate projects and everything works beautifully well.
So, the problem had nothing to do with incomplete debug information in Java class files. It was just a NetBeans peculiarity that this check box is off by default.
I am using intellij idea ultimate version 12.1.4 and trying to use maven with a project. Here is 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>
<parent>
<groupId>com.fasterxml</groupId>
<artifactId>oss-parent</artifactId>
<version>10</version>
</parent>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.2.2</version>
<name>jackson-databind</name>
<description>General data-binding functionality for Jackson: works on core streaming API</description>
<url>http://wiki.fasterxml.com/JacksonHome</url>
<scm>
<connection>scm:git:git#github.com:FasterXML/jackson-databind.git</connection>
<developerConnection>scm:git:git#github.com:FasterXML/jackson-databind.git</developerConnection>
<url>http://github.com/FasterXML/jackson-databind</url>
<tag>jackson-databind-2.2.2</tag>
</scm>
<properties>
<osgi.export>
com.fasterxml.jackson.databind,
com.fasterxml.jackson.databind.annotation,
com.fasterxml.jackson.databind.cfg,
com.fasterxml.jackson.databind.deser,
com.fasterxml.jackson.databind.deser.impl,
com.fasterxml.jackson.databind.deser.std,
com.fasterxml.jackson.databind.exc,
com.fasterxml.jackson.databind.ext,
com.fasterxml.jackson.databind.introspect,
com.fasterxml.jackson.databind.jsonschema,
com.fasterxml.jackson.databind.jsonFormatVisitors,
com.fasterxml.jackson.databind.jsontype,
com.fasterxml.jackson.databind.jsontype.impl,
com.fasterxml.jackson.databind.module,
com.fasterxml.jackson.databind.node,
com.fasterxml.jackson.databind.ser,
com.fasterxml.jackson.databind.ser.impl,
com.fasterxml.jackson.databind.ser.std,
com.fasterxml.jackson.databind.type,
com.fasterxml.jackson.databind.util
</osgi.export>
<osgi.import>
com.fasterxml.jackson.annotation,
com.fasterxml.jackson.core,
com.fasterxml.jackson.core.base,
com.fasterxml.jackson.core.format,
com.fasterxml.jackson.core.json,
com.fasterxml.jackson.core.io,
com.fasterxml.jackson.core.util,
com.fasterxml.jackson.core.type,
org.xml.sax,org.w3c.dom, org.w3c.dom.bootstrap, org.w3c.dom.ls,
javax.xml.datatype, javax.xml.namespace, javax.xml.parsers
</osgi.import>
<!-- Generate PackageVersion.java into this directory. -->
<packageVersion.dir>com/fasterxml/jackson/databind/cfg</packageVersion.dir>
<packageVersion.package>com.fasterxml.jackson.databind.cfg</packageVersion.package>
</properties>
<dependencies>
<!-- Builds on core streaming API; also needs core annotations -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.2.2</version>
</dependency>
<!-- and for testing, JUnit is needed, as well as quite a few
libs for which we use reflection for code, but direct dep for testing
-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>1.7.9</version>
<scope>test</scope>
</dependency>
<dependency> <!-- from core we just test for repackaged cglib, not hibernate proper -->
<groupId>org.hibernate</groupId>
<artifactId>hibernate-cglib-repack</artifactId>
<version>2.1_3</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<configuration>
<excludes>
<exclude>com/fasterxml/jackson/failing/*.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${javadoc.version}</version>
<configuration>
<links>
<link>http://docs.oracle.com/javase/6/docs/api/</link>
<link>http://fasterxml.github.com/jackson-annotations/javadoc/2.1.1/</link>
<link>http://fasterxml.github.com/jackson-core/javadoc/2.1.1/</link>
</links>
</configuration>
</plugin>
<plugin>
<!-- Inherited from oss-base. Generate PackageVersion.java.-->
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<executions>
<execution>
<id>process-packageVersion</id>
<phase>process-sources</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>release</id>
<properties>
<maven.test.skip>true</maven.test.skip>
<skipTests>true</skipTests>
</properties>
</profile>
</profiles>
</project>
When I do a maven dependency resolution, its taking forever to get it through and this is what I get:
And it sticks here forever.
Here are my maven settings:
I followed steps given in this SO answer.
Please let me know where am I doing wrong and how do I get rid of it.
EDIT
If this should help, I am trying to run this code: https://github.com/hmkcode/Android/tree/master/java-post-gcm
I am not sure whether its an issue with the pom.xml itself. Perhaps if someone is able to have it working on his IDE, it may be concluded that its an issue with my specific IDE config.
If this is an issue very specific to intellij, I would suggest do the following steps
You can try running mvn clean install.(Depending on your network speed it will pull every dependency)
Change intellij settings in
Preferences->build,execution,deployment->maven->Maven home directory->{now change this to point to your mvn home rather than bundled mvn}
mvn -v in command line should give you the maven home path.
Now it won't try to download dependencies again.
File | Settings | Build, Execution, Deployment | Build Tools | Maven |
Threads (-T option) | 8 (or however many threads you want to try)
mvn compile -T 8
I had the same issue. Maven was taking an hour in IntelliJ and also running from the command line. Using the -T parameter you can tell Maven to use more threads to download artifacts simultaneously. Takes only about 15 minutes now.
Don't use bundled mvn. Point "Maven home directory" to the path on your file system.
After you're done building. Check "Work offline". This stops mvn from searching remote websites each time you build. Uncheck when you update your POM file so it can search for the changes.
You can also skip tests. This is evertyhing from the command line.
mvn clean install -T 8 -o -DskipTests
Select File, Settings, then set VM options for Maven importing to -Xms1024m -Xmx2048m.
Visit https://www.programmersought.com/article/56414660398/
For me, issue was related to https://repo.maven.apache.org/maven2 and it was not responding.
I added another mirror(maven-central.storage.googleapis.com) in settings.xml
I am facing issues while using enum in my J2EE application. I am using enum in a switch case inside my stateless service bean.
During runtime I see following exception on switch statement:
Caused by: java.lang.NoClassDefFoundError: com/comp/service/TestServiceImpl$1
This issue has been extensively discussed on one of the thread on SO. But I do not see any solution mentioned to resolve this issue.
In my case I use JBOSS EAP6.1 server. JDK version is 1.7. Code is built using Maven in Eclipse IDE. And application is deployed as EAR archive. How do I add this extra generated class file in classpath inside my EAR archive? Is there any other way to resolve this issue?
Update 29 June 2014:
I tried to build application from command line. Then this extra class file is generated. And I am able to deply and execute application successfully. It seems to be bug with eclipse then. Any idea how to resolve it?
pom.xml from EAR project:
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>demo-maven</artifactId>
<groupId>com.comp.demo</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>demo-ear</artifactId>
<packaging>ear</packaging>
<name>demo - ear</name>
<url>www.comp.com</url>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<distribution>repo</distribution>
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
</license>
</licenses>
<dependencies>
<!-- Depend on the ejb module and war so that we can package them -->
<dependency>
<groupId>com.comp.demo</groupId>
<artifactId>demo-web</artifactId>
<type>war</type>
</dependency>
<dependency>
<groupId>com.comp.demo</groupId>
<artifactId>demo-service</artifactId>
<type>ejb</type>
</dependency>
</dependencies>
<build>
<finalName>${project.parent.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>${version.ear.plugin}</version>
<configuration>
<!-- Tell Maven we are using Java EE 6 -->
<version>6</version>
<!-- Use Java EE ear libraries as needed. Java EE ear libraries
are in easy way to package any libraries needed in the ear, and automatically
have any modules (EJB-JARs and WARs) use them -->
<defaultLibBundleDir>lib</defaultLibBundleDir>
<modules></modules>
<fileNameMapping>no-version</fileNameMapping>
</configuration>
</plugin>
<!-- The JBoss AS plugin deploys your ear to a local JBoss EAP container -->
<!-- Due to Maven's lack of intelligence with EARs we need to configure
the jboss-as maven plugin to skip deployment for all modules. We then enable
it specifically in the ear module. -->
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<!-- When built in OpenShift the 'openshift' profile will be used when invoking mvn. -->
<!-- Use this profile for any OpenShift specific customization your app will need. -->
<!-- By default that is to put the resulting archive into the 'deployments' folder. -->
<!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
<id>openshift</id>
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>${version.ear.plugin}</version>
<configuration>
<outputDirectory>deployments</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
pom.xml from ejb project:
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>demo-maven</artifactId>
<groupId>com.comp.demo</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>demo-service</artifactId>
<packaging>ejb</packaging>
<name>demo - service</name>
<url>www.comp.com</url>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<distribution>repo</distribution>
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
</license>
</licenses>
<dependencies>
<!-- Declare the APIs we depend on and need for compilation. All of them
are provided by JBoss EAP 6 -->
<!-- Import the EJB API, we use provided scope as the API is included in
JBoss EAP 6 -->
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the CDI API, we use provided scope as the API is included in
JBoss EAP 6 -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the JPA API, we use provided scope as the API is included in
JBoss EAP 6 -->
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- JSR-303 (Bean Validation) Implementation -->
<!-- Provides portable constraints such as #Email -->
<!-- Hibernate Validator is shipped in JBoss EAP 6 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.ejb3</groupId>
<artifactId>jboss-ejb3-ext-api</artifactId>
<version>2.0.0-redhat-2</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<!-- Test scope dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.5.Final</version>
<scope>test</scope>
</dependency>
<!-- Optional, but highly recommended -->
<!-- Arquillian allows you to test enterprise code such as EJBs and Transactional(JTA)
JPA from JUnit/TestNG -->
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-ejb-plugin</artifactId>
<version>${version.ejb.plugin}</version>
<configuration>
<!-- Tell Maven we are using EJB 3.1 -->
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<!-- The default profile skips all tests, though you can tune it to run
just unit tests based on a custom pattern -->
<!-- Seperate profiles are provided for running all tests, including Arquillian
tests that execute in the specified container -->
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${version.surefire.plugin}</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- An optional Arquillian testing profile that executes tests in your
JBoss EAP instance -->
<!-- This profile will start a new JBoss EAP instance, and execute the
test, shutting it down when done -->
<!-- Run with: mvn clean test -Parq-jbossas-managed -->
<id>arq-jbossas-managed</id>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-container-managed</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
<!-- An optional Arquillian testing profile that executes tests in a remote
JBoss EAP instance -->
<!-- Run with: mvn clean test -Parq-jbossas-remote -->
<id>arq-jbossas-remote</id>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-container-remote</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
I ran into a similar issue, and the easy workaround was to define the Enum as public instead of private.
(Didn't have time to verify, but my hunch is that this causes the class to not be created as Name$1.class but rather something like Name$Enumname.class, which seemed to be the problem)
In my case, to avoid that NoClassDefFoundError in the code line of the switch statement, the only solution i saw was to replace switch statement by "else if" statements:
if (enumValue == EnumClass.Enum1) {
....
} else if (enumValue == EnumClass.Enum2) {
....
} else if (enumValue == EnumClass.Enum3) {
....
} else {
....
}
Exception caused by:
Caused by: java.lang.ClassNotFoundException: com.test.services.impl.MyServiceImpl$1
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1358)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1180)
Test with Java 8, Tomcat 8.5, Spring boot.
I have a project configuration quite similar to yours: eclipse, Maven, JDK 1.6, JBoss EAP6.2, and I have the same problem with a java.lang.NoClassDefFoundError when using an enum in a switch case.
I have found a workaround for it: generate an ear file (it is a war in my case) and install it manually from the JBoss administration console. I noticed the war includes the $1 needed classes and then you won't get the exception.
This is just a workaround, but it works for me. A good point of this workaround is that subsequent deployments done through eclipse work!
I will be listening to the answers to your question because I want a real solution.
I'm using Eclipse Kepler with M2E plugin for Maven.
I want to create web-app Maven project using my "Util" Maven project - this is not a multi-module project. Just want this simple .jar in project, with possibility to edit "Util" project with enhancements and fixes during work with main project.
I have added only the maven dependency in webb app (no settings like build path, deployment assembly etc.) and Eclipse figured out automatically that this is project from workspace (simply: not seen as .jar with version number but with folder icon)
Now, when I install "Util" in maven repo and close project, everything works fine and Eclipse is deploying my util-0.0.1-SNAPSHOT.jar to web-inf/lib as working .jar file.
The problem is: when util project is opened, eclipse just creates "util.jar" in deployment (not util-0.0.1-SNAPSHOT.jar) and deploy it as "jar-like-war" with classes put in WEB-INF/classes/ instead of root of jar, so I end up with something like:
...\wtpwebapps\BigProject\WEB-INF\lib\util.jar\WEB-INF\classes\ which results with simple ClassNotFoundException, because "Util" projet is not a web project - only .jar with simple classes.
How to add Maven dependency on simple util project in web app, still having an option to edit util project any time in workspace?
Have the same setup like you and it works OK. When I work on small project and do mvn install JAR is not deployed at target as projName-0.0.1-SNAPSHOT.jar though. Do both projects have same <groupID>?.
EDIT:
Had some time and also had something ready so I did some tests. I am sorry for the long post but this is what works for me. I am working with the WildFly server.
1/<groupID> doesn't have to be the same after all
2a/Here is the pom.xml of the utils jar
<?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/maven-v4_0_0.xsd">
<!-- =========================================================== -->
<!-- Basics -->
<!-- =========================================================== -->
<modelVersion>4.0.0</modelVersion>
<groupId>so.examples</groupId>
<artifactId>utils</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>WebApp Common files</name>
<description>WebApp Common files</description>
<!-- =========================================================== -->
<!-- Properties -->
<!-- =========================================================== -->
<properties>
<!-- other plugin versions -->
<version.compiler.plugin>2.3.2</version.compiler.plugin>
<version.surefire.plugin>2.4.3</version.surefire.plugin>
<!-- maven-compiler-plugin -->
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
</dependencies>
</dependencyManagement>
<dependencies>
</dependencies>
<build>
<!-- Maven will append the version to the finalName -->
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.compiler.plugin}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
2b/ And the class file
package utils.commons;
public class PrintUtilities
{
public static String addArrowPrint(String toPrint)
{
return "--->"+toPrint+"<----";
}
}
3a/Here is the pom.xml of the webApp
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>so.examples</groupId>
<artifactId>webapp</artifactId>
<packaging>war</packaging>
<version>0.0.1</version>
<description>Main WebApp project</description>
<properties>
<!-- Explicitly declaring the source encoding eliminates the following
message: -->
<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
resources, i.e. build is platform dependent! -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- JBoss dependency versions -->
<version.jboss.maven.plugin>7.4.Final</version.jboss.maven.plugin>
<!-- Define the version of the JBoss BOMs we want to import to specify
tested stacks. -->
<version.jboss.bom>1.0.7.Final</version.jboss.bom>
<!-- other plugin versions -->
<version.surefire.plugin>2.10</version.surefire.plugin>
<version.war.plugin>2.1.1</version.war.plugin>
<!-- maven-compiler-plugin -->
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
</properties>
<dependencyManagement>
<dependencies>
<!-- JBoss distributes a complete set of Java EE 6 APIs including a Bill
of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection)
of artifacts. We use this here so that we always get the correct versions
of artifacts. Here we use the jboss-javaee-6.0-with-tools stack (you can
read this as the JBoss stack of the Java EE 6 APIs, with some extras tools
for your project, such as Arquillian for testing) and the jboss-javaee-6.0-with-hibernate
stack you can read this as the JBoss stack of the Java EE 6 APIs, with extras
from the Hibernate family of projects) -->
<dependency>
<groupId>org.jboss.bom</groupId>
<artifactId>jboss-javaee-6.0-with-tools</artifactId>
<version>${version.jboss.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.bom</groupId>
<artifactId>jboss-javaee-6.0-with-hibernate</artifactId>
<version>${version.jboss.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>so.examples</groupId>
<artifactId>jar_lib</artifactId>
<version>0.0.1</version>
</dependency>
<!-- First declare the APIs we depend on and need for compilation. All
of them are provided by JBoss AS 7 -->
<!-- Import the Common Annotations API (JSR-250), we use provided scope
as the API is included in JBoss AS 7 -->
<dependency>
<groupId>org.jboss.spec.javax.annotation</groupId>
<artifactId>jboss-annotations-api_1.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the JAX-RS API, we use provided scope as the API is included
in JBoss AS 7 -->
<dependency>
<groupId>org.jboss.spec.javax.ws.rs</groupId>
<artifactId>jboss-jaxrs-api_1.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the EJB API, we use provided scope as the API is included in
JBoss AS 7 -->
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the JSF API, we use provided scope as the API is included in
JBoss AS 7 -->
<dependency>
<groupId>org.jboss.spec.javax.faces</groupId>
<artifactId>jboss-jsf-api_2.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- Now we declare any tools needed -->
</dependencies>
<build>
<!-- Maven will append the version to the finalName (which is the name
given to the generated war, and hence the context root) -->
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${version.war.plugin}</version>
<configuration>
<!-- Java EE 6 doesn't require web.xml, Maven needs to catch up! -->
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<!-- The JBoss AS plugin deploys your war to a local JBoss AS container -->
<!-- To use, run: mvn package jboss-as:deploy -->
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>${version.jboss.maven.plugin}</version>
</plugin>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.0.1.Final</version>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<!-- The default profile skips all tests, though you can tune it to run
just unit tests based on a custom pattern -->
<!-- Seperate profiles are provided for running all tests, including Arquillian
tests that execute in the specified container -->
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${version.surefire.plugin}</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
3b/ and here are the class files:
RESTActivator
package webapp;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
#ApplicationPath("/root")
public class RESTActivator extends Application {
}
RestMethods
package webapp;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.ws.rs.*;
import utils.commons.PrintUtilities;
#Stateless
#LocalBean
#Path("/methods")
public class RestMethods {
#GET()
#Produces("text/plain")
public String welcomeMessage()
{
StringBuffer welcomeText = new StringBuffer();
welcomeText.append(" Called Rest Methods \n");
welcomeText.append(" ==================== \n");
welcomeText.append(PrintUtilities.addArrowPrint("Called Rest Methods") + "\n");
return welcomeText.toString();
}
}//class
4/ I first do a mvn clean install for the utils project. After it is installed in my local maven repo. Then do a update project with eclipse on my web app project and then clean package wildfly:deploy (server must be already started).
Then point your browser to http://localhost:8080/webapp/root/methods
Hope this helps.