Problems converting Dynamic Web Project to Maven - java

I'm using Eclipse Luna with Websphere Application Sever 8.5.
When I run a dynamic web project using the Websphere Application Sever 8.5 it runs fine.
However, when I convert a dynamic web project to a maven project, i'm getting around 53 errors starting with Missing artifact com.ibm.websphere e.g Missing artifact com.ibm.websphere.xml:xmlapi:jar:1.0.0' all located in my pom.xml.
I am also getting this error:
The container 'Maven Dependencies' references non existing library
C:\Users\Brian242\.m2\repository\com\ibm\websphere\ws\com.ibm.ws.wccm\1.0.0\com.ibm.ws.wccm-1.0.0.jar'
Not sure if that's part of the problem.
I've looked everywhere for a solution but haven't found anything. So I have decided to ask for some help. Does anyone know how to solve the above problem/s?
Thank you,
Brian
<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>TrialProj</groupId>
<artifactId>TrialProj</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.ibm.tools.target</groupId>
<artifactId>was</artifactId>
<version>8.5.5</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>

you created M2_REPO environment variable?
right click on the project root
Build Path-> Configure Puild Path ...
Click button 'Add Variable'
Click 'Set Variable ...'
Click 'New ...'
name: M2_REPO
Path: / path_to_repository_the_maven /
Click Ok
Recompile

If you are using eclipse make sure you add suport for eclipse web tools using:
mvn eclipse:eclipse -Dwtpversion=2.0
(2.0 or your required version) And afterwards recompile maven project:
mvn compile

Related

Why JRE Library is changed after Maven Update in Eclipse?

I'm an Intellij user and now I need to use Eclipse to create a Maven web app. So I installed Eclipse, I added Tomcat and all. And I want to use Java 8 for my projects, but I have a problem because I try to change JRE System Library from 1.7 to 1.8, and when I do Maven -> Update Project it becomes 1.7. And I don't understand why.
So I create a Maven project and I choose the webapp archetype from org.apache.maven and at the beginning my project has JRE System Library 1.7
After that I try to choose it like this:
After that the JRE System Library becomes 1.8:
After that I do right click Maven -> Update project and the JRE System Library becomes 1.7:
Why the JRE Library is changed from 1.8 to 1.7 after Maven update? And what should I do to have JRE System Library 1.8?
This is my pom:
<?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.abc</groupId>
<artifactId>firstwebproj</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>firstwebproj Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>firstwebproj</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Thanks in advance!
Look at your first picture. In the greyed out "Execution Environment" choice, the textfield has the content "JavaSE-1.7 (jdk1.8.0_201)". That JDK version is the same one you're trying to set it to use, but you have that JDK distro associated with Java SE 1.7.
In Eclipse Preferences, go to "Installed JREs", but go to the subfolder of that, "Execution Environments". In the left-hand list, you will see entries for "JavaSE-1.7" and hopefully "JavaSE-1.8". When you click each one of those, the right-hand list will populate with any available JDK/JRE installations.
You need to make sure that when you select "JavaSE-1.7", that NONE of the JDK 1.8 instlalations are checked in the right-hand list, and when you select "JavaSE-1.8, you have the desired JDK 1.8 distribution checked in the right-hand list.

spring-boot Maven: How to create executable jar with main class?

Recently, I wrote a Spring-Boot project and I wanted that Maven will be able to create a jar file that I'll be able to run by the command "java -jar ".
This is the pom.xml I wrote:
<?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>SpringBootGame</groupId>
<artifactId>SpringBootGame</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.3.RELEASE</version>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.3.RELEASE</version>
<configuration>
<mainClass>com.game.Main</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
In order to build the jar file, I had to run the command: "mvn clean package spring-boot:repackage".
My questions are:
Why must I add spring-boot-maven-plugin? I already have spring-boot-starter-web dependency that adds spring-boot as a dependency and maven-compiler-plugin that builds a jar file from the code?
Can you think about a way to configure pom.xml file that I'll be able to get the jar file using the "native" command "mvn clean package" and not the cumbersome "mvn clean package spring-boot:repackage"?
Thanks
Why must I add spring-boot-maven-plugin? I already have spring-boot-starter-web dependency that adds spring-boot as a dependency and maven-compiler-plugin that builds a jar file from the code?
Because the plugin is what adds Maven support for Spring Boot
Can you think about a way to configure pom.xml file that I'll be able to get the jar file using the "native" command "mvn clean package" and not the cumbersome "mvn clean package spring-boot:repackage"?
It looks like you are missing the <packaging>jar</packaging> element in between your <project> </project> element.
The reason you had to run that lengthy command, is because you did not include the <executions></executions> element when including the plugin. Please see section 71.1 of the following docs:
https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-maven-plugin.html#build-tool-plugins-include-maven-plugin
71.2 elaborates on the <packaging> element.
In the configuration of the maven plugin you have already in place, you need to add the executable block like :
<configuration>
<executable>true</executable>
</configuration>
this will create in the target folder the runnable jar that can be run by using java -jar command.

How to place folder/jar in Maven META-INF root

I am working on a implementation that requires UnlimitedJCEPolicyJDK8 for SAP hana cloud platform. The documentation tells me that i need to place it under the following structure:
WAR file:
META-inf
- ext_security
- jre8
The problem is when i include the jars it goes to WEB-INF/classes and thats not where the server is looking. As seen in the picture.
Technical details:
tomcat 8: v3.2 runtime
JRE 1.8
Maven build: using webapp archatype
With facades to support servlets.
IDE: eclipse
Tried the following:
add files using eclipse web deployment assembly (for what ever the reason it does not seems to work with maven and yes i use .m2 and WTP plugin)
Adding files trough maven dependency and tried copy to output folder.
i open WAR file moved files manually to correct folder and re-zipped and verified that if its in correct folder the update to server is working fine.
i really hope you can help me.
kind regards,
UPDATE: as requested by khmarbaise the pom file. And i created web-inf folder by myself in the hope it would be placed in root.
<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>hcp</groupId>
<artifactId>edi.web</artifactId>
<packaging>war</packaging>
<version>0.0.2-SNAPSHOT</version>
<name>edi.web Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- tried classpath but it did not seem to do annything
Below dependency is from local .m2 repository-->
<dependency>
<groupId>hcp</groupId>
<artifactId>jre8security</artifactId>
<version>1.0.0</version>
<optional>true</optional>
<!-- goes in manifest classpath, but not included in WEB-INF/lib -->
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Solution provided by pace:
create a source folder under the following name: src/main/webapp/META-INF
The maven-war-plugin's war goal has a configuration option webappDirectory. It defaults to src/main/webapp. Anything in there will be placed in the root of the war. So you could create a directory:
src/main/webapp/META-INF
and drop in whatever files you want there. I don't much about the web tools plugin so not sure what approach would work there.

Create tomcat - maven project with eclipse in ubuntu

I'm tring to create a webapp with maven on, I followed this guide: http://www.youtube.com/watch?v=YeC7XQho-O0
When I create the project it say this warning:
There are no JREs installed in the workspace that are strictly compatible with this environment. testM6 Build path JRE System Library Problem
My .pom file is
<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>ac.web.test</groupId>
<artifactId>testM6</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>testM6</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.4</source>
<target>1.4</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
when I try to switch to this build tag:
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
</plugin>
</plugins>
</build>
I get this warning:
Description Resource Path Location Type
Build path specifies execution environment J2SE-1.5. There are no JREs installed in the workspace that are strictly compatible with this environment.
testM6 Build path JRE System Library Problem
What I miss?
Thanks much to all
I resolved with this Warning - Build path specifies execution environment J2SE-1.4
but I did not understand why it does not automatically
Eclipse is creating your build path based on your POM file. Including the JRE system library. In your configuration of the compiler plugin you specified that your source code is Java 1.4 compliant and that you wanted it to be compiled as Java 1.4 compliant.
Eclipse warns you that it has no perfect match with a "build path warning" in your Markers view. Maven will do the same when run. If you did not configure the Eclipse run-configuration for your maven build with a JDK 1.4, then Eclipse will pick whatever JDK is available (default JRE) to run Maven and Maven warns you about the fact that it may not produce what you expected.
If you have a JDK 7 configured in Eclipse, then you need to set the following as the configuration of the compiler plugin:
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
After you have done that, the warning should go away. Both the Eclipse Marker and the warning that Maven spits out when run.
I see you have java 1.5 installed in your system and you are trying to use Tomcat 7. According to this link the minimum requirement for running Tomcat 7 is java 1.6.

Maven is not automatically building default folder path in eclipse

I am using Eclipse Indigo. I installed the maven package on eclipse. I configured the Pom and nearly everything is fine. Just maven is not building the default folder bath
src/main/java
Here is the pom.
<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>TestProject</groupId>
<artifactId>TestProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.0.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<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>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.6</version>
<configuration>
<ajdtVersion>1.6</ajdtVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
I cleaned the project,installed and build it.... also I upgradet the project... the dependencies are all fine... no error at all.. why isn't the folder build ?
Eclipse's integration with maven is (to say at least) appalling. If you want to create a new project: create the pom and the folders, and then run mvn eclipse:eclipse to create the project files for eclipse. The simple solution that I've followed for a couple of years is to use the community edition of Intellij.
Aswering your second question: well... again, the integration is so poor that sometimes you'll need to close and reopen the project for eclipse to read the new changes. Most of the time, a refresh + clean project will force eclipse to read the project configuration.

Categories