eclipse workspace is closed problem - java

How to get access to eclipse workspace from java program.
When I use IWorkspace workspace = ResourcesPlugin.getWorkspace().getRoot() it gives me exception like this
java.lang.IllegalStateException: Workspace is closed.
at org.eclipse.core.resources.ResourcesPlugin.getWorkspace(ResourcesPlugin.java:329)
at amdocs.amsp.test.EMFCodeGen.load(EMFCodeGen.java:37)
at amdocs.amsp.test.EMFCodeGen.main(EMFCodeGen.java:26)
can you tell me how to get access to workspace from a standalone java program out side of eclipse. (of ourse there is a classpath with all the jar required for that)

Are you trying to do it in OSGi based application (eqinox for example)? Because workspace is created upon start of org.eclipse.core.resources bundle that should be managed by framework, exception of yours means that bundle probably didn't start yet.

As far as I understand this, the workspace retrieved with ResourcesPlugin.getWorkspace() is the workspace the running Platform is using, if Platform.isRunning(). So if you are running a plain Java application, not an Eclipse application, there is no such thing as the workspace.

If you want to run your application like this it must be headless. Following you can see how to create a headless project:
Going Headless

Related

Why does opening python script in eclipse assigns python nature to my project

I have a maven parent project that consists of a a web project and ear project. Projects are j2ee and targeted for websphere runtime.
Inside the parent project are websphere administration python scripts. When I open these scripts to view or edit them eclipse automatically assigns the org.python.pydev.pythonNature to the project and I get a red X indicating python is not configured.
I have to continuously open and deselect the project nature and reopen the project. Is there a way to make it stop doing this?
Well, as you saw, the pythonNature is automatically added to the project whenever a python file is opened... this is working as designed.
I didn't understand why you're fighting that... I.e.: why didn't you just configure the interpreter and let the pythonNature there?

Is there any guide showing how to build effectively an application with appengine and maven in eclipse?

I'm trying to develop an application using Google App-Engine and Maven using Eclipse. I am facing a problem where by whenever you change a CSS or JSP file, a restart of the application is required. This makes working quite difficult, since a reload takes a lot of time.
For example when you develop on tomcat no need for restart is required when such a change is made, only Java or xml file require restart of the server.
Is there a solution that mimics the tomcat behavior on GAE SDK when developing on localhost?
If you've built using the standard app engine maven archetype, when you run mvn appengine:devserver from you -ear directory, the exploded war working directory is located here:
<yourapp>/<yourapp>-ear/target/<yourapp>-ear-1.0-SNAPSHOT/<yourapp>-war-1.0-SNAPSHOT.war
If you change any JSPs in this directory, they will get reloaded without needing to restart the devserver.
Thus, you can set up a simple script or command that copies all your JSPs and static files from /-war/src/main/webapp to that deploy directory whenever you want your files to be refreshed. I saw on some threads where people set up their IDE (in this case IntelliJ) to automatically do that copy whenever the IDE loses focuses, which makes it trivial to get pages reloaded.
Building application with appengine in eclipse using maven is not very effective and time consuming because on every change on jsp/css/js with a traditional approach there is a need to restart appengine or mvn appengine:devserver.
#adevine make me thought about a solution, and I found this link: http://andrei.gmxhome.de/filesync/index.html wich installs a plugin in eclipse, then I activate the project to sync files from myapp/src/main/webapp to a target folder generated by maven myapp/target/myapp-snapshot-0.0.1.
It's working!!!
Whenever a change is done in webapp the files are transfered automtically(no need to run anything else, just save the file) to the target folder and are reloaded successfully.
Hope this could help people because its frustrating working with appengine(restarts takes a lot).

Java: How do you debug a module/jar that works as a plugin for another application

I know this sounds like a pathetic question and I'm sure it will get ridiculed but thats the only way I know how to describe the situation.
Scenerio : I'm creating a plugin for another java application. This application that uses the compile jar (my plugin) gets placed in the applications plugin directory. Is there anyway I can go about debugging this jar (which I have to source to) in execution of an application I do not have the source to?
I'm using Eclispe Juno as my IDE.
I would say yes, if you can start the application that you plugin plugs in into :).
java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=n myapp
to start then in eclipse setup a remote-debugging session setting it up to connect to your app running in the java debug mode to the localhost on the port 4000
This linky will probably solve all your eclipse problems
http://javarevisited.blogspot.com/2011/02/how-to-setup-remote-debugging-in.html

Getting Eclipse project info within an OSGi application

I'm working on a project which inspects Eclipse Java projects and getting some information of source files, using Eclipse AST. Right now it's an Eclipse plugin, but we need to make it independent from Eclipse, we are using only AST libraries of Eclipse.
I've tried copying required JAR's and run the project as a normal Java app(not an Eclipse plugin, not dependent to Eclipse) but then I started getting some errors, because when I run the app outside of Eclipse, AST can't get needed information(project data) from Eclipse and returning null for some cases. For example, when I visit a method invocation(MethodInvocationNode class), I need to know which class's method is this, but I can't because of AST errors I explained(MethodInvocationNode.resolveMethodBinding() returns null in this case).
I think I need to get an IProject, in Eclipse plugin I'm getting that from IWorkspace(ResourcesPlugin.getWorkspace()) which I think available in all Eclipse plugins.
Now, I think if I can make an OSGi app of it, maybe I can somehow get that IProject but I have no idea how can I do that. Documentations and tutorials didn't help much. It's also high probability that I'm missing some fundamental points about Eclipse projects and/or OSGi apps :) .
In short, how can I get IProject data within an OSGi app?
First, every Eclipse application is an OSGi-application, so there is no difference in doing things in a pure OSGi environment or Eclipse.
Second the "Workspace" is an Eclipse specific construct, so making your application "independent" from Eclipse makes no sense at all, the contents of a project, especially Java projects are eclipse specific (so you also have to parse the .classpath files with API from Eclipse to know which resources have to be compiled, parse .project files, etc).
The workspace mechanism is part of the bundle org.eclipse.core.resources. You need to include that in your OSGi application. Like already mentioned you can access all things the same way like in an Eclipse environment.

NetBeans - Java EE server classpath is not correctly set up - server home directory is missing error

I am getting an error when I try to build my project in NetBeans. I am using JBoss 5.1.0 server and have attached that to my project. The error is -
The following error occurred while executing this line:
.../myPath/build-impl.xml:176: The Java EE server classpath is not correctly set up - server home directory is missing.
Either open the project in the IDE and assign the server or setup the server classpath manually.
For example like this:
ant -Dj2ee.server.home=<app_server_installation_directory>
I am using Mac OS X Lion.
I was missing a library. When I right clicked the project and went to libraries, it showed me library missing. I added the library and did a clean and build and the error disappeared
Clean builds did not help me, either. I took a look at project.properties and found that j2ee.server.home was not set anywhere, although j2ee.platform.classpath depends on it.
I do have Weblogic Server set up under /home (on a Linux machine).
So, I closed the project and added a line to project.properties:
j2ee.server.home=/home/blister/wls/wlserver
(where wlserver = the server name)
And reopened the project. Presto, the app now builds. It still doesn't know where the app server is, but at least I can built my jar and can worry about deploying it later. (I tell it to build a war which deploys nicely to Weblogic.)
If you are using netBeans Ide, then right click on the project. click properties. in the properties menu select Run. in that the first text box is server. There select the server. with which u want to run the project. If the server details are not configured before. configure server details and try. it wil help you to solve the above problem.
This worked for me.
Right click on the Project -> Properties -> Run
And Change the server Setting from the current server to another sever and click OK.
Wait for any background scanning to finish.
Repeat the processes 1 to 3 again this time selecting the actual server you want to run the code on.
Then try Re-Running your application.
I also had this error. However despite adding servers in the Run section of the Properties window, repeatedly no servers showed as being available to add to the Project ( again within the Run section ). The solution to being able to see a server in this server list was to run Netbeans as an admin ( which I saw Rotunba referencing in this thread..It was then possible to add a server and the project built successfully..
I solved it like this, I added in the ANT properties field
"j2ee.server.home=http://localhost/"
tolls>options>java>Ant
this in linux netbeans
It could also be as simple as not running your IDE i.e. netbeans as an administrator on your machine. I had the same problem. Wasted some time.

Categories