multiple issues with spring tool suite 3.6.3 release - java

I have wanted to learn Spring MVC and I took look at javavids - YouTube, I wanted to follow along with this series but I have multiple problems/issues
First I rebuild the Global repo in Maven Repositories
Solved
then I created Maven project but structure in videos was
but I have this instead
Solved
OK now I want to add plugins to pom.xml but getting this dialog
in videos it shows :
UPDATE
I don't get any plug-in to select from
Solved
I also have compiler compliance
when I set compiler to java 1.7 then I get
Solved
and at last when I tried to update STS 3.6.3 It freezes and shows
OK
I have proxy settings as
Update
I make changes and add dependency according to this Answer
I get this error:
Now I don't see resources which can help me to get these remaining issues resolved!
any help is highly appreciated.

First maven default compiler level is set to 1.5.
In order to set it to 1.7 either configure maven-compiler-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
or add the following properties.
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
After setting java version press Alt+F5 to update maven project.
In order to search for dependency or plugins go to Window -> Preferences -> Maven and check Download repository index update on startup
Restart STS, wait for index updates to complete.
Regarding your project structure check do have <packaging>war</packaging> in your pom.xml. By default it will be jar type.

then I created Maven project but structure in videos was
You be able to switch the perspective in the ide (eclipse). In the video that is the Java EE-Perspective.
That what you got is the Spring-Perspective, don't worry about that.
Window -> Open Perspective
OK now I want to add plugins to pom.xml but getting this dialog
Ok, what is wrong with that?
If you searching for a dependency on MVN Repository there you got all informationen to fill out the informations you see in the dialog. Otherwise you can open the pom-file and paste the dependency directly.
I also have compiler compliance
Assuming that you are using the m2e plugin in Eclipse, you'll need to specify the source and target versions as 1.7 for maven-compiler-plugin.
specify it with this:
<properties>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
</properties>
And update your project Right click on project -> maven -> update project (Alt F5)
The network seems to be ok. Are you on a privat or office network?

I would also like to recommend to get started with Spring using the Spring Tool Suite by using Spring Boot and the guides at http://spring.io/guides. You can import those guides directly into STS and start from there (assuming you have network connectivity).

I think the solution I am providing here will dam sure will work for you.
If you have downloaded Spring STS successfully then you have to follow these steps only.
After creation of project right click on project and Update Maven Project
For Integrating it with Google App Engine it is very Simple. You have to just declare the google app engine dependency in you pom.xml. I am providing you the structure of my Google App engine Spring project.
Please follow these steps
1. create appengine-wex.xml under WEB-INF Folder
2. Create logging.properties file under WEB-INF Folder
3. Insert Google App engine dependecies
Here is sample appengine-web.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xml>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>make-me</application>
<version>2</version>
<!--
Allows App Engine to send multiple requests to one instance in parallel:
-->
<threadsafe>true</threadsafe>
<!-- Configure java.util.logging -->
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
</system-properties>
<!--
HTTP Sessions are disabled by default. To enable HTTP sessions specify:
<sessions-enabled>true</sessions-enabled>
It's possible to reduce request latency by configuring your application to
asynchronously write HTTP session data to the datastore:
<async-session-persistence enabled="true" />
With this feature enabled, there is a very small chance your app will see
stale session data. For details, see
http://code.google.com/appengine/docs/java/config/appconfig.html#Enabling_Sessions
-->
</appengine-web-app>
Pom dependency
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>1.9.1</version>
</dependency>
<!-- JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-testing</artifactId>
<version>1.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-stubs</artifactId>
<version>1.9.1</version>
<scope>test</scope>
</dependency>
Final Structure

Related

Hibernate MultiMap cannot be found while code generation

While i'm trying generate some classes by Hibernate using existing db relation it generates some error:
org.hibernate.console.HibernateConsoleRuntimeException: Received a NoClassDefFoundError, probably the console configuration classpath is incomplete or contains conflicting versions of the same class
Received a NoClassDefFoundError, probably the console configuration classpath is incomplete or contains conflicting versions of the same class
org.hibernate.console.HibernateConsoleRuntimeException: Received a NoClassDefFoundError, probably the console configuration classpath is incomplete or contains conflicting versions of the same class
Received a NoClassDefFoundError, probably the console configuration classpath is incomplete or contains conflicting versions of the same class
java.lang.NoClassDefFoundError: org/apache/commons/collections/MultiMap
org/apache/commons/collections/MultiMap
java.lang.ClassNotFoundException: org.apache.commons.collections.MultiMap cannot be found by org.jboss.tools.hibernate.runtime.v_5_1_5.0.1.Final-v20160331-1852-B88
org.apache.commons.collections.MultiMap cannot be found byorg.jboss.tools.hibernate.runtime.v_5_1_5.0.1.Final-v20160331-1852-B88
My maven file:
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.firebirdsql.jdbc</groupId>
<artifactId>jaybird-jdk18</artifactId>
<version>2.2.10</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.2</version>
</dependency>
I see apache common-collections jar in Maven Dependencies and i am able to use apache's MultiMap in my code.
I had the same issue. Here is how I fixed it:
Open Edit Configuration dialog and go to Classpath tab, remove project-name (default classpath), click the button "Add Projects..." to add your project.
Then it works.
Or you can try using previous version instead of v5.1. In hibernate perspective, "your configuration" / Edit configuration, Change hibernate version to previous version like v4.3.
Just to chime in: Eclipse Mars. Hibernate 5.1.0. JDK 8. As Gordon and Kevin mentioned above, changing the version of Hibernate to 4.3 in in Edit Configuration worked for me.
I changed the hibernate version of 5.1 to 4.3 in Console Configuration file.
Set hibernate perspective
Open Hibernate configuration tab
Click right on your configuration
Select Edit configuration
Change Hibernate Version of 5.1 to 4.3
Fix for me: Mars worked with Hibernate Tools plugin v. 5.1.4. I just needed to click "update" after "search for updates"

Eclipse Add Project1 as dependent and auto import its dependents

I am trying to get used to Eclipse/Java but am more familiar with MS VisualStudio. Lets say I have Java Library (Project1) which has some dependencies on jar files via Properties->Java Build Path->Libraries (eg: AWS SDK, gson, swagger, etc). Now if I have Project2 and set a project dependency for Project2 to Project1 via Properties->Java Build Path->Project, I would hope that Project1 dependents would also be included for Project2. I dont see that happening or I am missing a step. I have been googling but I don't see any tutorial/documentation discussing 2 levels of dependents. I see that the Project1 jar is being referenced but what about the dependents for Project1? I am receiving an error such as:
The type XXXX cannot be resolved. It is indirectly referenced from
required .class files XXXX
I strongly suggest using Maven, which is a great and easy to use dependency manager.
Probably your eclipse already comes shipped with it, all you have to do is:
Do this for both projects:
Right click both projects, go to Configure -> Convert to Maven Project.
Create a group id,artirfact id and specify the version for your projects.
It will generate a pom.xml file in the root of your project.
Something like this:
<?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>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
</dependencies>
</project>
You can add dependencies for your projects just by adding a dependency tag.
<dependency>
<groupId>yourGroup</groupId>
<artifactId>yourProject</artifactId>
<version>1.0.0</version>
</dependency>
After that just right click your projects go to
Run -> Run Configurations -> Maven Clean
Run -> Run Configurations -> Maven Install
and it will automatically download and install your dependencies for you.
You might want to have a look at Maven or a tool like this (Gradle, Ivy...) to handle your dependencies.
Relying on Eclipse for defining your build process (and dependencies) is a bad idea for long term projects.
This depends a little, on your project.
In case it is just a Java project, then it is better to use a build tool like Ant with Ivy, Maven or Gradle. As these contain the dependencies and other configuration details. Eclipse Mars (v4.5.1) comes with build in support for all these build tools.
In case it is an Eclipse Plug-in which you are developing, then you can configure it in Eclipse. And then store the configuration files, with the source code in the code repository.

Native Library already loaded in another Maven plugin's classloader

I would like to run two third-party Maven plugins using the Xerial JDBC driver for SQLite. The plugin configuration roughly looks like this:
<plugins>
<!-- reset database with the SQL Maven plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<executions>...</executions>
<dependencies>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
[...]
<!-- generate source code with the jOOQ Maven plugin -->
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<executions>...</executions>
<dependencies>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
[...]
Now this SQLite JDBC driver loads a native library, internally, which causes the following error to appear in the second plugin's execution:
java.lang.UnsatisfiedLinkError: Native Library
C:\Users\Lukas\AppData\Local\Temp\sqlite-3.7.151-amd64-sqlitejdbc.dll
already loaded in another classloader
The workaround is to comment out one of the plugins.
Is there a proper way to circumvent this problem without making any assumptions about the system on which this runs? I'd like to create self-contained tests with the above, which should run on any system, i.e. putting stuff into system library paths is not a solution here. Can this be solved with Maven? Or do any of the above plugins or (more likely) the JDBC driver need to be fixed?

Eclipse + Maven + JavaServer Faces -> ClassNotFoundException: StartupServletContextListener

Summary
When I try to run a JSF 2.0 application from within Eclipse (on Tomcat 7.0) I get the following exception:
Problem: SEVERE: Error configuring application listener of class org.apache.myfaces.webapp.StartupServletContextListener
java.lang.ClassNotFoundException: org.apache.myfaces.webapp.StartupServletContextListener
Details
I'm learning to develop JSF applications, using Eclipse.
I started with a preconfigured Eclipse project: File->New->Dynamic Web Project->JavaServer Face v2.0 Project.
Using this method Eclipse provides all dependencies. But I want to really learn how everything works. I want to remove the "magic", so I converted my project to a Maven project: Configure->Convert to Maven project.
I then created my pom.xml (based on http://myfaces.apache.org/build-tools/archetypes/myfaces-archetype-helloworld20/index.html), it contains the following:
<build>
<finalName>jsf-facelets-tutorial</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>WebContent/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-api</artifactId>
<version>2.0.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-impl</artifactId>
<version>2.0.5</version>
<scope>runtime</scope>
</dependency>
</dependencies>
But because I'm unfamiliar with JSF, and because this is an Eclipse "Dynamic Web Project", the project structure is new to me and I'm having trouble understanding which dependencies are coming from Maven and which are provided by the Eclipse "magic".
In Eclipse, my project structure is as follows:
ProjectName
JAX-WS Web Services <-- CAN I REMOVE THIS???
Deployment Descriptor
Java Resources
src/main
Libraries
Apache Tomcat v7.0
el-api.jar
jsp-api.jar
[more...]
JSF 2.0 (Apache MyFaces JSF Core-2.0 API 2.0.2) <-- I REMOVED THIS!!!
EAR Libraries
JRE System Library
Maven Dependencies
el-api-1.0.jar
myfaces-api-2.0.5.jar
myfaces-impl-2.0.5.jar
[more...]
Web App Libraries
Problem
My (very basic) application (login page & welcome page) no longer runs.
When I do the following:
(1) Right click on WebContent/login.xhtml
(2) Run as -> Run on Server
(3) Apache Tomcat v7.0 - JDK6 at localhost
I get the exception:
Problem: SEVERE: Error configuring application listener of class org.apache.myfaces.webapp.StartupServletContextListener
java.lang.ClassNotFoundException: org.apache.myfaces.webapp.StartupServletContextListener
I have the feeling that this is very easy to fix, but I'm too unfamiliar with these frameworks to work it out.
If there are any additional details I should provide (web.xml, faces-config-xml, login.xhtml), let me know and I'll add them.
Thanks!
EDIT
WEB-INF/lib is always empty. From my understanding, it's necessary to copy all dependencies into this folder, that will be required at runtime, and that are not provided by the Web Container. The reasons mine is empty are: (1) I don't know what I need in there (2) I don't know how to automate the process of putting .jar files in there
Under your eclipse Project Properties, select Deployment Assembly from the navigation menu which defines "packaging structure for this Java EE Web Application project." Make sure you have all the project dependencies added here..
Or look into web server directory under workspace/.metadata/.plugins/org.eclipse.wst.server.core\tmp0 to check if the jars have been copied to catalina base.
Sounds like you don't have all the jars in your target folder ready to deploy to tomcat
Try running a maven package in eclipse, right click on project, run as maven package

Best Approach to Set Up External Dependency in Maven

I hope I'm explaining this as accurately as possible, and I want to know if I set up the maven dependencies correctly, or if there's a better way to do it.
Most of my development team's projects rely on a home-grown jar that is deployed at server class loader. The reason for this jar to reside at this level is to the ease of updating the jar at one place without repackaging each project that's using it, assuming changes made to it are backward-compatible.
I develop my web apps against Jetty in my local development. So, in order for the web apps to work locally, I set up the dependencies this way:-
<dependencies>
<!-- Configuring external jar dependency -->
<dependency>
<groupId>com.test.app</groupId>
<artifactId>app-jar</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${env.EXTERNAL_JAR}</systemPath>
</dependency>
...
</dependencies>
<build>
<plugins>
<!-- Configuring Jetty -->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.26</version>
<configuration>
<contextPath>/${project.parent.artifactId}</contextPath>
<jettyEnvXml>${env.JETTY_ENV_XML}</jettyEnvXml>
<scanIntervalSeconds>1</scanIntervalSeconds>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>7777</port>
</connector>
</connectors>
<webAppConfig>
<extraClasspath>${env.EXTERNAL_JAR}</extraClasspath>
</webAppConfig>
</configuration>
</plugin>
...
</plugins>
</build>
In this approach, I set up an environment variable that points to the external jar path, and reference it in my pom.xml as ${env.EXTERNAL_JAR}.
After doing some reading, it seems like using "system" scope is considered a bad practice. So, I installed this external jar in Nexus and change the scope to "provided":-
<dependency>
<groupId>com.test.app</groupId>
<artifactId>app-jar</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
This allows me to compile my project properly, but I'm not sure if it is even possible for me to get rid of the "EXTERNAL_JAR" environment variable completely because it's still needed by Jetty for the runtime to work properly. My take is using "provided" scope is a little tedious and more work, because I now need to remember to update the jar in Nexus when it is modified AND I still need to update the jar located at the path pointed by the environment variable.
Is there a way for me to expose the external jar to Jetty through maven dependencies, yet not being packaged into the project when the war file is built?
What are you advice on this? Should I just stick with "system" scope so that I just need to update the jar at one place, or should I use "provided" scope? Or if there's even a better way to do this?
Thanks much.
You should be able to add dependencies to the jetty plugin. And then I have the provided scope for the project itself.
http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin
as in
<project>
...
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<systemProperties>
<systemProperty>
<name>logback.configurationFile</name>
<value>./src/etc/logback.xml</value>
</systemProperty>
</systemProperties>
</configuration>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>0.9.15</version>
</dependency>
</dependencies>
</plugin>
...
<project>
The best thing to do is setup an external repository with your dependency, and add it to your pom.
<repositories>
<repository>
<id>my-repo</id>
<name>my-repo</name>
<url>http://your.repo.url</url>
</repository>
</repositories>
and then you can add your dependency as
<dependency>
<groupId>com.test.app</groupId>
<artifactId>app-jar</artifactId>
<version>1.0</version>
</dependency>
I approve of provided. Provided means - download the dependency for compile-time, but I expect to see it on classpath on the application server.
I did not realize you care only for your local development, so the following would be useful if you were running Jetty on an external server:
Maven will let you deploy a file to a server using the Wagon plugin. So a part of your build process could be pushing the proper .jar into your Jetty server. That way you would not have to do it manually. I would prefer this solution to running a local Maven repository on the Jetty server as suggested by #Paul.
If you wanted to be super-clever (usually a bad idea), you might try to set up a repository directly on the machine with Jetty, that would serve the jar directly from your Jetty install. That way you would not have to modify Nexus, the jars would be only at one place. You can even set up Nexus to mirror another repository, so it could pick things up automatically.
It is a bad practice to modify .jar contents and keep the same Maven coordinates. So this "clever" approach would not work that great anyway.

Categories