I've been working on a rather "standard" Java web application for a long time now. I develop in Eclipse using Eclipse's server plugin to run the app in Tomcat. The app's setup is straight forward: Spring for bootstrapping, Wicket for web, Hibernate for ORM, Maven for dependency management.
Today I have added Akka 2.0 to the project. I added it to my POM as per the manual:
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor</artifactId>
<version>2.0.2</version>
</dependency>
Maven finds the dependency and I can see it showing up in the Maven dependencies in Eclipse's package explorer. The referenced Scala Library also shows up (version 2.9.2 as it seems).
I can use the library just as one would expect: Eclipse finds the classes, I can jump to source files etc. Everything works perfectly. But once I start the app and it comes across any part of the program with references to Akka it throws a NoClassDefFoundError.
Since all other libraries still work as expected, my best guess is that is has something to do with the fact that Akka is a library developed in Scala. Since I've hardly used Scala myself though, I could not find any solution to the issue myself and Google isn't really that helpful when it comes to such generic exceptions.
Do you have any advice?
Verify that the required library (AKKA) is in your deployment assembly under Eclipse: open the project's properties and look for "Deployment Assembly" on the left.
[I'm using Eclipse Indigo]
You could verify the presence (or lack) of the expected jar file by examining the deployment under tomcat.
Related
I am trying to set up tomcat server for gwt application. I would like to configure server to update my server side code changes immediately.
While looking for some helpful examples over the web, I found that there are to plugins for maven.
One from:
org.codehaus.mojo (which also provide plugin for gwt in maven echosystem).
And second from: org.apache.tomcat.maven.
What is the difference between them? Which one should I choose for:
GWT 2.7 Maven Project. I will develope app in Eclipse IDE. So I would like to have good integration with it to. F.e.: the Eclipse tab/view "Servers".
From https://tomcat.apache.org/maven-plugin-2.2/
This is the new home for the Tomcat Maven Plugin (previously hosted at Codehaus).
The CodeHaus Mojo (now MojoHaus) Tomcat Maven Plugin is obsolete.
I have Maven archetypes that use the Tomcat Maven Plugin to fire up a server for development, with automatic redeployment of the webapp when classes change, at https://github.com/tbroyer/gwt-maven-archetypes
Note that they use a different Maven Plugin for GWT than the one from MojoHaus (ex-CodeHaus Mojo), one that works much better with multi-module builds.
I've never used Eclipse WTP though (tried it and had too much trouble, probably because I didn't really know how to use it properly though) so I can't really comment, but I see no reason why it wouldn't work.
I am following an online tutorial, and am stuck trying to get Spring libraries to run things with. The instructions are either a little out of date or assume I know how to do things in a Maven world that I do not.
They give web addresses on the Spring site from which they say I can "download the jars". But you can't download jars from any of them; evidently what you can do is find pom.xml fragments and use them to download jars. If you know how.
For example: the tutorial says:
Finally, following is the list of Spring and other libraries to be
included in your web application. You simply drag these files and drop
them in WebContent/WEB-INF/lib folder.
commons-logging-x.y.z.jar
org.springframework.asm-x.y.z.jar
org.springframework.beans-x.y.z.jar
org.springframework.context-x.y.z.jar
org.springframework.core-x.y.z.jar
org.springframework.expression-x.y.z.jar
org.springframework.web.servlet-x.y.z.jar
org.springframework.web-x.y.z.jar
spring-web.jar
I love the "simply" here.
I have many but not all of these (version 3.2.4). I have googled the library names and used jarfinder for the ones I don't have, but haven't found them all. It seems to me I'm flailing around a bit, just trying this and that until something works. I hate that.
I'm hoping someone can give me a set of steps I should follow when faced with this sort of thing, since we're faced with it all the time. Do I need to stop my current study of programming and learn Maven inside and out so that I can configure the bloody system so I can program again?
Is it a maven project you have?
If so in the pom.xml you just need to place the “pom fragments” in the xml.
i.e. between the dependencies tags. For example,
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>
</dependencies>
Once you have done that run maven install. Under Eclipse it is: run as > maven install.
That will download all the dependences i.e. jars you have listed into the you local maven repository.
I think the default is C:\Users\yourName\.m2\repository
Found most of the needed jar files here:
http://www.java2s.com/Code/Jar/CatalogJar.htm
while I downloaded commons-logging here:
http://mvnrepository.com/artifact/commons-logging/commons-logging/1.2
My advice is, stop study you program language, Java I guess and learn how to integrate maven dependencies of Spring in your Maven project.
http://spring.io/blog/2009/12/02/obtaining-spring-3-artifacts-with-maven/
You cannot start the house from the roof
Dependency issues, we've all dealt with them, but I'm mostly used to C# and now working in Java so I have some questions.
Let's say I add a library to my project, called ExtLib.
ExtLib has a certain library included in its lib-folder, let's call it LogLib-1.0.
I'm using Eclipse and I've made a User Library for ExtLib, included its main jar file and all of the files in its lib-folder. So far so good.
But now I want to do some logging of my own, so I make another User Library and add the newer LogLib-1.1 to it, because it has some new features I want to use.
Can I ever be sure I'm not breaking ExtLib this way?
I know .NET uses the Global Assembly Cache and methods like that, but I have no clue how Java handles this. I tried Googling, but didn't find much, a few mentions of the Classloader here and there, but nothing helpful.
Can anyone tell me what a proper way to deal with this issue is? Or is it no issue at all?
In this specific case (LogLib-1.0 and LogLib-1.1) we're dealing with the same library that is both a direct dependency of your application, and a "transitive" dependency via the ExtLib. In this situation, dependency management can come to help.
It will probably reason that LogLib-1.1 is a backward compatible release of LogLib-1.0, and it will decide that your application can run fine using only LogLib-1.1.
In the Java world, tools like Maven, Gradle or SBT exist to help you in this. Maven is the most widespread, and other tools often are compatible with Maven.
Usage
To solve this situation using Maven, you would add a file called pom.xml to your application, stating it depends on LogLib version 1.1. That might look like this (note that this example is pure fiction):
<dependency>
<groupId>org.loglib</groupId>
<artifactId>loglib</artifactId>
<version>1.1</version>
</dependency>
The ExtLib you're using also has a pom.xml shipped with it, and it might state
<dependency>
<groupId>org.loglib</groupId>
<artifactId>loglib</artifactId>
<version>1.0</version>
</dependency>
Maven (or any other tool) would decide that including LogLib-1.1 is sufficient to get your application running. When using Maven, mvn depedency:tree helps you visualise that.
Deployment
With respect to the packaging / deployment question: mvn package will package your application to a jar, war or ear archive, including only the dependencies you need (and not two versions of the same lib). This makes you don't have to worry about the order in which your application server reads the jar files.
I'm having some issues making the maven google app engine plugin work properly.
First of all, I'm not even sure if the archetype I'm using is the correct one, their examples show version 0.7.0 but it seems like never versions exist (i tried 0.9.1 and that works), where can I find a overview of what versions of the plugin is available?
Secondly, the archetype seems.. messy, I don't like the package structure and it doesn't seem to actually include the GAE and GWT dependencies. I have to manually add them to my project in Eclipse, which kind of defeats the purpose of using maven. And how come they are breaking the gwt maven plugin? I know that one includes the actual gwt jars as maven dependencies?
I'm fairly new to Maven, but I have been using the gwt maven plugin for a while, and I'm very happy with everything about it. Is there any way I could just their archetype to do the base project and add the gae plugin to it?
UPDATE
I suspect the problem I'm seeing with the GAE maven plug-in is in regards to undefined properties in the POM. I have no idea if its due to error these aren't set-up or if its due to me actually have to manually set them up. The documentation on this plugin is sparse.
Thanks for the answer below, but I really don't want to add another archetype into play. I think the best solution for me is to try and adapt a GWT maven project manually, to include support for GAE.
I've used the archetype like so :
http://code.google.com/p/gae-mvn-archetype/
to generate a GAE project template.Then manually added my other dependencies. This got me a usable project which I can deploy to GAE and everything.
Also, for Eclipse importing, once the template project was done, I've imported it into eclipse using the m2_eclipse plugin :
http://m2eclipse.sonatype.org/installing-m2eclipse.html
(note that i've imported it into Eclipse as a Maven project, NOT as an Eclipse whatever project)
This imported the thing into eclipse with all the necessary dependencies and without errors.
I have a project I need to release the source for. The problem I have is that I need to create a source release for all code that we have developed. The code is across multiple projects, but I want to leverage maven so that only the source for the jars we are actually using is released.
For example:
core code project (multi module maven project)
web app project (multi module maven project). Contains we app module plus some supporting jar modules. Depends on some jars from core code project.
Now I want to release all the source for the web app project but only the source for the core code project that the web app uses.
Can I do this with maven?
I have a feeling it is possible with assembly plugin and source plugin but it is not clear to me how to put this together.
First of all your question is bit unclear. let me assume certain things and proceed.
I believe that following is your folder structure.
web app project
some source code folder
pom.xml
core code project
some source code folder
pom.xml
Take the core code project and change the version from previous version in pom.xml.
let 's say if it was 1.0 change it to 1.1
<groupId>core code project related</groupId>
<artifactId>core code project</artifactId>
<name>core code</name>
<version>1.1</version>
Make your changes to accomodate the web app project in core code project.
later,
in web app project add dependency for core code project in pom.xml
<dependency>
<groupId>core code project related</groupId>
<artifactId>core code project</artifactId>
<name>core code</name>
<version>1.1</version>
</dependency>
In this way, 1.1 version of core project will have only web app related code.
Currently we are using this method. Hope it helps. let me know if you want something else.
I have a feeling it is possible with assembly plugin and source plugin but it is not clear to me how to put this together.
If I understood the question correctly, one solution would be to create an "aggregator" project listing all wanted modules (the relevant modules from the webapp and the relevant modules from the core) and to use the source:aggregate goal from the Maven Source Plugin.
I'm unsure why you want to do this, the pom from your web app project will explicitly list the versions of your code dependencies used, so you can find the source easily. It sounds like you want to store the same artifact twice. So if your web app uses core-x-1.2.3.jar and core-y-4.5.6.jar you would produce a web app sources artifact containing the source from both those core jars in addition to the actual web app source?
You can use the maven versions plugin to update your web app pom to use the latest versions of your core dependencies, I've automated that by running a shell script in a CI server in the past. That means whenever you release a new version of your web app you will be using the latest release of your core code, and all you need to do is update your web app pom from version control.