Accessing values in HttpServlet in Google Web Toolkit - gwt

I am getting the following error:
java.lang.NoSuchMethodError: org.apache.commons.fileupload.servlet.ServletFileUpload.getItemIterator(Ljavax/servlet/http/HttpServletRequest;)Lorg/apache/commons/fileupload/FileItemIterator
though I have added commons-io 1.2 jar and commons-Fileupload 1.2.1 jar in my buildpath.
Please help me out.

There is probably an incompatibility between the file-upload version you're using and the servlet.jar you have on your server.
I can't tell you if it is between the "commons" jars or between the server jars and "commons".
Anyway, I suggest you use a maven (or gradle even better) project at least to get your jars in a consistent way. If your project is not ready, you can still pack your application as a war and get the correct jars from the zipped output fil of your maven compiling.

Related

CDI imports cannot be resolved in Eclipse

i have written an application on my pc using CDI as the backing bean for jsf, the application works completely fine.
Now i setup everything on a new pc, installed glassfish 4.1, setup eclipse kepler by putting the installed jre as jdk7 from the glassfish folder.
when i make a war for the application on my pc and deploy it onto the glassfish server on the other pc everything works fine.
now i tried taking the project from my pc and imported it onto the new pc. the eclipse on the new pc wont recognize import javax.enterprise.context.SessionScoped; giving compiler error that this annotation is not available.
The import javax.enterprise.context cannot be resolved
it doesnt recognize javax.enterprise.context.* at all. like CDI is not available. i am using JDK 7 which contains JSR 346, so i am completely confused what the issue could be.
if i deploy the application directly through the glassfish admin console using the war file it works perfectly fine but if i try to publish it through eclipse, it gives me unresolved compilation errors
Eclipse did not import ALL glassfish jars, so you need to:
Right Click on the project name, Build Path, Configure build path, under Libraries Click Add External Jars, go to where you have extracted Glassfish and import all jars that exists in:
glassfish4\glassfish\modules
and all sub directories two, like endoresed.
This will fix the problem for CDI and other stuff lik JAX-RS
If I had to guess, your .project and .classpath files are pointing to JAR locations that are specific to your old computer.
This is why people like build tools such as maven, or gradle, you can pick up and reimport a project; it'll resolve all dependencies for you.
Do you happen to use the GlassFish Tools plugin for Eclipse? I found that the GlassFish System Libraries classpath container, which is created implicitly by that plugin and which is added to all projects that specify a GlassFish server as their runtime, misses cdi-api.jar. This is where the javax.enterprise.context.* package is located (and many others).
So I could fix this by adding cdi-api.jar as an External Jar to the build path. After that, you may get a warning like Classpath entry [...]/cdi-api.jar will not be exported or published. Runtime ClassNotFoundExceptions may result., which can be eliminated by using the Quick Fix to Exclude the associated raw classpath entry from the set of potential publish/export dependencies. That JAR file is already contained in the modules folder of GlassFish, obviously.
Maybe this problem only occurs with the GlassFish Web Profile, at least that's what I use.

M2E WTP Copy Provided Jar

I have a custom classloader jar <scope>provided</scope> that must be in tomcat/lib before my webapp is run or else it fails to start. I'm using WTP. Is there some way that I can configure M2E/WTP to automatically copy this custom jar to tomcat/lib during the deploy process?
Edit:
It doesn't have to be using WTP, I could also use, for example, a solution using tomcat6-maven-plugin.
For running an embedded Tomcat instance with the Tomcat Maven plugin, add the JARs required in the Tomcat lib dir as dependencies of the Tomcat plugin itself as shown in this example with the derby and javamail dependencies.
I spent a lot of time researching this problem and here's what I've found:
The tomcat6-maven-plugin does not properly emulate the tomcat boot order, as seen in this jira issue as well as their tomcat6-maven-plugin source.
However, after more research I discovered another maven plugin that I didn't know existed: cargo. Thanks to their excellent documentation I was able to get my project running with the custom (and picky) class loader jar.

Netbeans Maven project to IDEA 12

Short version: I would like to deploy Maven generated WAR to Local Tomcat server and not to build the war with internal IDEA process since the produced WAR file is not the same as the Maven generated one.
Long version: I have been using the Netbeans IDE for my Maven Java project. One of the modules is packaged as a WAR and should be deployed to tomcat server.
In Netbeans when I selected "Run" on the Web Module it asks for application server configuration then it runs the maven 'package' goal and deploys the application(generated WAR) to the Tomcat Server probably via Tomcat manager. So far so good.
We are now in the process of switching to Scala language. Scala classes extend old Java classes and the project is now "Mixed". I have configured Maven to compile the project as a mix of scala and java code. Maven produces a WAR which can then be deployed to Tomcat server without trouble - everything works as it should.
Now I would like to switch to Intellij-idea 12 IDE. But I have a problem: IDEA is refusing to deploy Maven created artifacts and insists of building one by it's own. The war is not the same and can't be used. Is there a way to tell IDEA to use Maven generated WARs and not try to make it's own ?
Just for the record I have already read these articles:
http://riddhimandas.com/blog/111
http://www.jetbrains.com/idea/webhelp/configuring-web-application-deployment.html Manually build WAR by IDEA - Want the maven generated one
IntelliJ IDEA: Maven, project compilation and deployment There is a hint here that IDEA can deploy Maven artifact from the 'target' directory but there is no information on how to do that.
With the help of CrazyCoder I figured it out.
You can make Intellij-Idea to upload your war by selecting External Source
But that's not all, even if you have a context.xml file difining your Context Root inside your WAR file: http://docs.oracle.com/javaee/1.4/tutorial/doc/WebApp3.html
You must specify one for every artifact you deploying (Unless someone will correct me)
The before launch section can be used to tell Idea what to Maven Goal to Run if any

NoClassDefFoundError on Java EE server in eclipse with tomcat

I'm trying to build a hello world application utilising GCM for Android notifications. When developing the server part, I'm not entirely sure how to get the gcm-server.jar file into the project. I've added it to the build path and Eclipse finds it perfectly fine, but when I build and deploy the project to a tomcat server (from within eclipse) it's throwing the following error at runtime:
java.lang.NoClassDefFoundError: com/google/android/gcm/server/Sender
I'm assuming I'm doing something wrong when importing the jar. What exactly is the procedure for getting a jar into a dynamic web project using Eclipse?
Going to answer my own question because I just got it working.
Turns out adding the .jar's to the Java build path is not enough. Tomcat has a seperate classpath for each project, and won't see the classes in the jar unless you dump the jar files into the WEB-INF/lib folder (which Eclipse does not do automatically).
You need to include the jar file for json. This question seems to have been repeated a few times.
http://code.google.com/p/json-simple/downloads/detail?name=json-simple-1.1.1.jar

Netty eclipse "no mandatory external dependencies"? import errors

I just downloaded Netty for a personal client-server-project from here:
http://netty.io/downloads/netty-3.3.0.Final-dist.tar.bz2
On the download page http://netty.io/downloads/ it says there are "no mandatory external dependencies". You only need a JDK 1.5 or higher. So I just set up a java project in eclipse IDE using my 1.6 JDK and got multiple errors saying "import cannot be resolved".
Examples:
org.jboss.logging, com.google, org.osgi, javax.servlet
That tells me that there are actually some external libraries needed. Or am I doing anything wrong?
Can anyone tell me where to find all these libraries since I could not find any clues on the Netty pages where to get them (I know that javax.servlet is part of Tomcat and JBoss AS distribution, but why do they then say that no external libraries are needed).
Are you trying to build netty from source? There's a pom.xml file in the root, implying that netty can be built by maven. You'll find all those dependencies in the pom file. "No mandatory external dependencies" means that you need no jar other than the netty jar to run your application. External dependecies is probably needed for some of the examples, definitively for testing and perhaps for some special, but optional, run time features.
The dependencies are only used for building and are marked as optional. The dependencies are only needed if you want for example use slf4j for logging in netty. Beside this netty can be used within your project without pulling in any third-party dependencies.