Where can I find the jar file or the source code of JEE6? Or is there another way how you can get autocompletion for this in Netbeans/Eclipse?
And I have just installed glassfish so that i can use JAX-RS but i do not understand how it works. Why does the javacompiler find these classes but netbeans does not? I building with maven2 but have not set any paths or so.
And why am I not able to install JEE6 without glassfish? I just do not need an application server for a REST service with Jersey.
Best regards,
CQQL
Question #1:
See this example project.
The example project is built with maven, which may answer your question about auto-complete. Netbeans 6.8+ (approx) has built-in maven support. After the first build of the example project, I think you'll see that auto-complete works better for any dependencies (i.e. jersey) inside the pom.xml. In my Netbeans, auto-complete works, but the javadocs are not there, which may mean that Jersey wasn't bundled with them.
Question #2: Your maven on the command line and the one inside Netbeans are different copies. You can make Netbeans use a specific copy of maven in Tools/Options/Misc/Maven/External Maven Home. This may clear up some confusion.
Question #3: Jersey can run in Tomcat or Jetty if you find Glassfish to be too much app server for your needs.
Related
I'm having trouble in implementing file upload handling with Jersey, Glassfish 4 and Netbeans. I know there are a lot of tutorials out there but all of them use maven projects.
Like we know that in Netbeans web application project, after we choose Glassfish as the server, we can use all of the JEE API cause automatically Netbeans add JEE API from Glassfish to our library (like in the picture below). I think its only for compiling and not included in the deployed war.
We can even make a new non web Java application and use JEE API by adding Java EE 7 API to our library, its just API for compiling, in the runtime all of the classes are provided by the server (like in the second picture ).
Now, I want to use the Jersey Multipart API for handling file upload. Glassfish already has the required jars in its modules folder, like jersey-media-multipart. (3rd picture), I know that they are provided in the runtime but I need them to compile my project. Simply adding the jars to the project library is not a proper way cause it gives me a lot of weird errors and we know we shouldn't cause Glassfish already provides them.
I need something like Jersey Multipart API to compile the project so that in the runtime the project uses all of the classes that Glassfish already provides. Just like the Java EE 7 API Library that Netbeans provides and work well.
Well, here's the solution...
If you only add the jersey-media-multipart, you'll get error HttpReader not found so you need to aadd all of the jersey jars in the glassfish modules.
Next, right click on the libraries folder in the netbeans project and in the compile tab, uncheck all of the jersey jars in the package column to make them get excluded when we build/ run the project .
Hope this helps anyone who have similar issue.
This question already has answers here:
How to include libraries in Java without using an IDE
(6 answers)
Closed 8 years ago.
I'm trying to use a java lib to connect to a database, im doing the tutorial outlined here, http://www.homeandlearn.co.uk/java/connect_to_a_database_using_java_code.html
and I can get it to work in netbeans by putting the .jar into the library file in my project file but I don't have a clue how to get it to work hen using an ide such as vim. can someone help?
If I got your question right, you can find the right answer on this other StackOverflow post: how to include libraries in java without using an IDE
You need to build both files into a JAR file, then you can run it.
I hope this helps.
A build tool which features dependency management such as Maven will help solve this problem. To use Maven you will add the location of libraries you require to an XML file (pom.xml) and Maven will download them for you and incorporate them in your target application archive (e.g. a war file).
Maven central provides a means to search for dependencies. In your case you can find the Derby client jar here. Click on the version of the library you would like to use and you'll see the sections of build descriptor code you needs to copy and paste in for: Maven, Ivy, and a few other popular build/dependency management tools.
Once you are comfortable with Maven, you could look up the Maven "Shade" plugin which will help you create a single jar file containing the necessary dependencies to run your application.
Vim, is more of an editor than an IDE, so you will need to specify the library .jar files manually on your class path when running your application.
You can do this by specifying the -cp parameter to the Java executable. e.g.
java -cp driver.jar MyMainClass
The way you are trying to use the library you desired requires manually adjusting your CLASSPATH. Oracle has some detailed instructions on that: PATH and CLASSPATH.
Though, I would suggest to use some kind of build tool which makes it easier to handle your applications dependencies.
In the Java world, the most convenient tools are Ant, Maven and Gradle.
I feel you have just started Java development, so I would prefer Gradle in your case, although Maven is still pretty widely used in projects.
With these build tools handling dependencies will not be -lets say- wired in the IDE and you can easily build your application in any environment.
I have a web application that is structured into a standard war. I want to use embedded Jetty server as my servlet container. Since this is all one code base, I figured that the main() that executes the Jetty server would also be in my war with the rest of the code.
So how do I go about executing my main(), which is in the war, to launch the Jetty server? I looked at the examples but the examples do not have this setup, which to me seems like a normal setup.
Would the Jetty server need to be told where the war file is (the war file that happens to be where its also located) or would Jetty by default find and check WEB-INF for the various XML files what Jetty processes?
I see something close to this using the Jetty Maven Plugin, but the consensus is that that plugin is not for production.
I was able to setup an executable file easily using the Maven plugin called Jetty Console Maven Plugin There is not much documentation about how to use it on the Internet. The author, simplercity, took down their blog entry for how to use it. But I did find one post on stackoverflow on how to use it.
The current version of this plugin is 1.55. It can be found here. One issue that I encountered is that while most of the artifacts that are required for this plugin are on version 1.55 one of them, jetty-console-ajp-plugin, is on version 1.53. This caused a problem for me because when I had all the other plugins set to 1.55 there was a signer exception error I got when I tried to execute my war. I found the solution in this stackoverflow answer. The fix was to use only 1.53 version of all the plugins. There might be a better solution that allows you to use 1.55 with 1.53 ajp-plugin. Other than that the plugin worked great and I implore the author of Jetty Console Maven Plugin to either bring his blog post on how to use it back up or create new documentation for it.
To execute a standalone application in Java it doesn't need to be a war. A jar is fine enough. A war contains information about how a web archive/application should be deployer into a J2EE container. When you run it standalone this isn't necessary. The main method will be enough. You can have a look at maven shade plugin. It will help you build a runnable jar.
(As a sidenote - a runnable jar is a rather simple thing. The manifest file of the jar file needs to contain the key MainClass and that is it.)
See title. I would also like the project to redeploy after every change. I am new to this area so my knowledge isnt that good. I tried googling and searching here, but I can't find any answer.
thanks for any help
There are two plugins that combined together in Eclipse work quite well together to perform what you want:
M2E: M2Eclipse which handles everything related to Maven.
Eclipse Web Tool Platform (WTP): which handles everything Java EE related (Tomcat, JBoss, etc...)
For M2E to work properly with WTP, you need to add m2e-wtp. You may find several useful information as well as some good links here.
I would start from the Eclipse Java EE distribution (it includes already Eclipse-WTP) and then add M2E (either with their update site or through eclipse market place: look for M2E and M2E-WTP).
From there, you create a Web Project and you can run it on a Tomcat server. The first time you try to run you project on a server, you will install Tomcat and it will appear in view named "Server". Double click on the server to configure ports, automatic deployment etc...
You can easily deploy a webapp using the Cargo Tomcat plugin. Here's helpful articles on this topic:
Maven Tomcat Deployment using Cargo plugin.
Autodeployment with Maven, Tomcat, and Cargo.
I need to have a Java EE project generate a WAR file automatically - preferably exploded - as opposed to choosing Export -> War file.
I have played with the various server definitions but have not been able to get either the Java EE preview or the HTTP server to work, and before installing each of the external container specific servers I'd like to hear if anybody has made this work.
So, question is: Which steps to take to have a WAR deployment automatically created and maintained by Eclipse?
EDIT: This is Eclipse 3.5 Java EE, and it is a Dynamic Web project in Eclipse. I want the WAR file/tree to be easily copyable to a network drive to be accessible for the target host. It runs an embedded Jetty, but I am interested in the generic WAR.
MyEclipse can do this, but we are standardizing on plain Eclipse.
EDIT: This particular web application will run inside an embedded Jetty. Since this question was asked we have found empirically that we need to have the complete tree containing the application with embedded Jetty, war file (exploded) and all built by the Hudson server in order to avoid human steps in the build-deploy-process. The answer for us therefore is scripting with ant (using ant4eclipse).
EDIT 2012: The ant4eclipse approach proved to be generally too inflexible and fragile in the long run, so we have switched to Maven. This solved very many problems, this one included.
Make an ant task to build the war (and copy if you like). Then add an Ant builder to the project (project -> properties -> builders). As long as your project is configured to build automatically the war will always be upto date.
This would equally work with maven, or pretty much any other build tool.
You should be able to do this with "File" -> "Export", scroll down to "Web" -> "WAR File" and follow the instructions
Have a look at this question. It refers to 3.2 version, but I believe that it still holds, until up to 3.4 version at least. It seems there is no automatic way of doing the Export - War thing.
Consider the solution given by Pablojim and drop the Export facility.