The import javax.ws cannot be resolved with GWT on Eclispe - java

I want to use some javax annotation on a GWT app. I download javax.ws.rs-api-2.0.jar here, and then include it in my project (Project/Properties/Java Build Path/Libraries/Add External Jars).
I clean my project, then I refresh my project and build it. But when I launch the Run as button, I got following error:
[ERROR] [gwtinit] - Line 5: The import javax.ws cannot be resolved
Eclipse show me no error in my source file, what did I miss?

With GWT you cannot use all Java libraries available for server side Java. You are restricted to a small JRE emulation subset.
As a consequence you cannot use any librariy using standard Java classes outside of the emulation subset.
Often there are special GWT libraries for the same purpose.
You don't get an error in eclipse because Eclipse interprets your code as standard Java. It doesn't know anything of the GWT restrictions. This is a common pitfall for everbody new to GWT.

Related

use org.eclipse.core.resources method in my java app

I have a java application in eclipse luna. In my workspace there are a few large projects.
I want to use org.eclipse.jdt.ui functions, and first I have to get the workspace with ResourcesPlugin.getWorkspace() method.
Apparently as a Java application, I cannot use ResourcesPlugin functions. There are a large number of Java class files so I am not able to import into the eclipse workspace as a project.
So, my question is: can I use methods from org.eclipse.jdt.ui and org.eclipse.core.resources (programmatically), and if I can, how?
With a few exceptions you can't use any Eclipse plugins in an ordinary Java program. You certainly can't use UI and resources code.
This is because the plugins rely on the Eclipse plugin support code being initialized properly when Eclipse starts.
You can write an Eclipse 'headless' application which lets you run without the GUI.

Using boilerpipe on Android application

I'm trying to use boilerpipe in an Android application.
I have included the libraries boilerpipe-1.2.0, nekohtml-1.9.13, xerces-2.9.1 in the libs folder.
When running the application with Eclipse i get the following error: Conversion to Dalvik format failed with error 1
It doesn't give me errors in the code. I'm also using the same code in a Java project and it works.
Could it be a problem of conflicts through dependencies?
The reason is dalvik uses different libraries than jvm.
I've created boilerpipe which uses correct ones: boilerpipe-android

How to generate JSR-172 stubs

Back in the old times, the Sun Java dev. toolkit (v2.x) used to have a stub generator tool, but no longer in 3.x versions. I can still use the old generator, but it is very picky when it comes to input WSDL files, and the errors generated do not contain any useful info to fix the WSDLs. The company that develops the SOAP WS is providing me with WSDLs not compatible with JSR-172, and I need to prove I'm using the the last official tool available to show there's no problem on our side.
I have installed the last reliable version of JavaME SDK (3.4) available at Oracle's site. These 3.x versions do not include an IDE, instead they provide plugins for Netbeans and Eclipse. I'm an Eclipse person, but I've opted for the Netbeans approach because looks easier to configure.
So I've downloaded the last Netbeans version (7.4). I've downloaded the bare-minimum JavaSE only version, then installed the mobility plugin for JavaME (Last time I needed to install Netbeans, you had to install the full JavaEE IDE plus GlashFish servers, etc. So glad to know they now offer the option not to install the full IDE).
Added the JavaME SDK v3.4 in platforms, but it does not detect it automatically. I was forced to configure a custom platform, but then the ant build failed. To solve this, I've installed the JavaME SDK v3.2 as well, which is detected by Netbeans out-of-the-box and builds fine.
You might think the stub generator tool would be available by now. Wrong!. You still have to go and install the "SOAP Web Services" netbeans plugin, which in turn installs a ton of other dependent plugins (by now the lightweight JavaSE install has become the bloated JavaEE-ready IDE that Netbeans has always been).
So then I created a basic JavaME project. Right-clicked over Source packages, then selected "New" -> "Java ME Web Services Client". The stub generator dialog is finally shown (and it looks pretty much like the old Sun Java CLDC 2.5.2 tool). I select the WSDL input file, type the client name and package name, and also ticked the "Generate databindings structures" checkbox (which I don't know what the heck it is for, but suffice to say I've tried both w/ and w/o this option selected and the result is the same).
Then I click the Finish button and only a .wsclient file (along with the imported wsdl file) is created. What is the purpose of this file? But most importantly, where are the .java or .class files? They are nowhere in the project folder!
Questions:
Is it possible to generate JSR-172 stubs using Netbeans?
If not, is it possible to do this using the Eclipse JavaME plugin?
It turns out there is a problem with the input WSDLs. They are valid but something is wrong because Netbeans does not generate any java file.
I've tested again with a known good WSDL and it works, so the procedure I followed is correct.
UPDATE:
I was using a local WSDL input file, and due to a bug in the SDK, if the file path contains whitespaces, the stub generation fails. In NetBeans no error is shown.

How can I convert an eclipse-dependent application into an eclipse-independent application?

I developed an application in eclipse that uses many of the classes of the eclipse framework and requires eclipse to run. But now I'm being required to decouple it from eclipse and make it a standalone application. How can I do this?
You might have luck using File / Export... / Java / Runnable Jar File. This will create a standalone .jar file that should be possible to run without Eclipse. You may however need to experiment with the various settings to get it to behave exactly how you want depending on what libraries you are using.
In general however, I'd suggest using a proper build/dependency management tool such as Maven. This will take a bit of time to learn at first, but my experience is that it will make you more productive in the long run....
Start by commenting out the imports for the offending libraries. This will turn red any references to those libraries in your code. Then substitute a different library or refactor your code.
What do you mean by "decouple" it from eclipse? Do you mean you can no longer rely on any of the eclipse libraries, or that you simply don't want it running as a module in the IDE?
If it's the former, you have a lot of rewriting to do.
If it's the latter, then you'll want to basically bundle your module with an "empty" eclipse framework application. This doesn't "unbundle" eclipse, eclipse is still there, but now you don't have any of the IDE modules etc, and instead you have a stand alone ECLIPSE BASED application.
Create a standalone jar file from the Eclipse project as mentioned by Mikera, or you need to re-factor the code such that it doesn't depend on Eclipse libraries.
There is no point in creating a Java application which depends on certain IDEs or platforms. Java code should be independent (which is why it has the power to run on any platform which has JVM installed in it.
Try removing the dependency from your project to the Eclipse libraries. See if you can simulate the same thing using Standard Java libraries. If not, try to create a JAR for your project from Eclipse. If nothing works out, try looking for some 3rd party APIs.

Is there a tool that checks GWT JRE emulation library violations?

I'm trying to port a Swing application to GWT.
However lots of this application classes use things that are not supported by GWT JRE emulation library such as java.util.Locale, java.text.SimpleDateFormat and much more.
Is there a tool that scans a project and spots such problems?
The Google Plugin for Eclipse shows errors for things that are unsupported by GWT's JRE emulation. http://code.google.com/eclipse/
The GWT compiler will complain if you try to access classes in the JRE that are not supported.
My GWT plugin does not warn until the end of a compilation process.
I fixed this issue by the following way.
In eclipse,
Create a java project.
Remove JRE from class path.
Go to gwt-user.jar. Locate java emulation classes. The path is like that: ..super../emul/java/...
Copy them to your java project.
What we get So far, your Java project without JRE have java.lan. and etc. classes.
This will work except com.google.gwt.lang.Array.java will be missing.
I created that array class (you can find it from internet, I couldn't locate it inside jars).
Add gwt-user and dev jars to the classpath.
Now, your own library can use only gwt java emulation and other gwt classes.
Eclipse will automatically warn you if you access a non emulated Java library.

Categories

Resources