Unable to launch a java/javaFX code after a clone on IntelliJ - java

It's very complicated to explain so sorry if it's not clear. Basically, I'm on a group project in javaFX, and every time I clone it, my PC doesn't recognize either Java or JavaFX on THAT project exactly. All the others work fine. So I have to do a lot of manipulation each time for it to "work" (I explain below).
And today I have clone because of an error. Except that impossible to make it work again.
What I did on IntelliJ after cloning:
-I reloaded the MAVEN project
-I imported the java libraries
-I put the right folder in ROOT
-I created the configuration
From there, Java and JavaFX are recognized. After that, I have other problems. In particular that of "The output path is not specified for module structure" and after that it redirects me to File -> Project Structure -> Project and compile output. Except that in my previous problems, I didn't have to define a Compiler Output. Usually the steps above were enough. And the problem is that I have no idea what to put in this section. I searched all over the internet, but 90% of the time it's an old version of IntelliJ and it was asking them for a path. There, I am asked for a file (impossible to choose a destination path, it is greyed out). And in CTRL C + V the path directly (for example an excluded "Out" folder like what I have read on the internet), I have this error at launch:
Error occurred during initialization of boot layer java.lang.module .FindException: Module start.structure not found
I want to re-specify that there is no error in the code, we have exactly the same with my team, and with them it works without worries.
If someone know how to resolve theses problems

This isn't really fully answerable here in a general sense, because there are too many environmental and project-specific things that may occur.
Instead, I'll provide a suggested approach for a new project:
Create a new JavaFX project in Idea.
Choose Maven for the build tool.
Follow the execution instructions from the linked documentation to ensure the project runs in your environment.
Share your new JavaFX project on GitHub.
Clone the newly shared project to a new Idea project.
This is emulating somebody else checking out the project from GitHub.
Run the newly checked out project in your Idea environment exactly as you did for Step 1.
That is really all you need to do to use JavaFX + Idea + GitHub.
A pre-existing project may require additional steps for configuration and use which may be project specific, so I can't generally advise on that.
Some comments on the approach outlined in your question:
You mention "every time I clone it".
You only really need to clone a project once, after that you can just update it.
The image has a folder ${project.build.directory}.
That looks wrong, kind of like an expansion variable name was applied literally rather than being expanded (I don't know what you did to cause that).
Your resources folder isn't marked with a resources icon.
This indicates that you haven't imported the project from Maven correctly.
Normally Idea will recognize a Maven project and import it automatically, mapping the standard directory structure, e.g. src/main/java is Java source and src/main/resources are resources.
"I have put the right folder in ROOT"
I am not sure what that means, but it should not be necessary to manually configure things like this. As mentioned, Idea knows the standard Maven project structure and is able to apply it without manual intervention.
"I created a configuration."
You don't need to create configuration manually.
The configuration you have created is wrong.
If you right-click on your JavaFX application class and choose run, an appropriate run configuration for the application will be created automatically.
The configuration does not need to specify a JavaFX SDK.
You don't need to (and should not for this purpose), install a JavaFX SDK on your machine.
The configuration does not need to specify a module path or modules to add.
Idea and Maven are smart enough to know that:
your application is modular (because you have provided a module-info.java)
the required modules are provided as Maven dependencies (this includes the JavaFX modules that you need)
the modules should be placed on the modulepath (Idea and Maven will do this automatically, you don't need to do anything manual for this to occur).
For the message "The output path is not specified for module structure":
I don't know what this means, but, if you follow the suggested approach, you don't need to manually specify an output path, Idea and Maven will automatically assign appropriate values and use them without user intervention.
"Error occurred during initialization of boot layer java.lang.module .FindException: Module start.structure not found"
This indicates that you have specified somewhere that a module start.structure should be used and either:
Your application's module (specified in its module-info.java) is defined using a different name.
Your application's source code is not on the module path (perhaps it is mistakenly on the classpath instead).
Your apps module isn't correctly added.
Usually Idea will be smart enough to know that you have a module-info.java and therefore to place your application code on the modulepath, so you don't need to manually specify modulepath and add-modules options to find your application's module.

Related

Steps to change IntelliJ GitHub project to download and build source code for dependencies

Using IntelliJ IDEA, it is often a straight-forward task to check out a project from GitHub and get it to build locally.
Once the base project is imported from GitHub, the IDE will download artifacts which will allow the main project to run. The dependencies can be examined by using File > Project Structure... > Libraries.
So the IDE downloads dependencies to allow running, but not to build from source. The IDE is able to decompile classes, but the IDE will not automatically download the source code for those dependency libraries so that the programmer can alter the code.
This question is about the steps required in the IDE and project configuration such that a selected dependency will be built locally, and thus allow the programmer to alter the code.
What I tried was to import the project on which the main project was dependent, as a separate project, then configure the main project to utilize the local project instead of the downloaded artifact. The first step, downloading the sub-project and getting it to compile, was completed successfully.
So I ended-up with two projects, the main one, and the one on which the main project depended. The task at hand, if this was the appropriate way to get this done, would be to open the main project and take some action to convince the main project to use the local build, rather than the downloaded runtime "jar".
First, I edited the POM.xml to comment out the dependency for the sub project. Checking File > Project Structure... > Libraries, I could see that it was gone, and the build now failed (as expected).
I went to File > Project Structure... > Libraries > + (plus sign) and poked around with New Module, and Import Module, but I was not able to convince the original project to use the locally available sub project. The result from various attempts was that code in the base project was not able to import from the sub project (unable to compile).
What are the specific steps to take in the IDE to get what was a runtime dependency "jar file" to instead to build locally, and use that instead?
Use a SNAPSHOT version for the dependency (you'll need to change this in both your project's pom.xml and the dependency's pom.xml, so if the current version is 2.0.0 change it to 2.0.0-SNAPSHOT)
Then you can edit the dependency's code and run mvn install in the dependency to provide the new version of the dependency to your project.
TLDR: there is no simple and straight-forward way of downloading a project's code and the code of its dependencies to rebuild it in one go as a complete chain.
Your project depends on several other artifacts. From the screenshot, we may assume that this is a maven project, at least we can be sure that there artifacts with compiled classes available for download, because this happends during build. You can view the compiled classes of your dependencies, because Intelli has the capability of decompressing jars and decompiling code, obviously, but the contents you are viewing is read-only.
Sidenote: Maven convention is to create 3 separate jars for each project. One with compiled classes, one with source files only and one with generated documentation. By default intellij may not download these, but you can force it (right-click on pom.xml -> maven -> Download sources and documentation). This will attach the actual source code instead of decompiled classes to your IDE, so it's much easier to understand the code - but still, there is no option to modify it - it's still read-only extract from some jar.
So what if you want to actually edit the source? You have 3 options, all with its own set of problems that need human intelligence to solve:
You extract the decompiled source from classes jar
You extract the attached source from sources jar
You check out git repository of the dependency
Now, beware of the downsides of each approach:
You can be sure that the decompiled source matches your project dependency 1:1. But decompiled code is not easy to read, missing comments, etc. Also, some projects may not ship their build scripts with the classes jar. Anything more complex than mvn clean install may turn out to be a blocker.
You can be reasonably sure the code matches your project dependency, but this actually is not a given. There is a chance of human error, causing the sources to actually not match the compiled classes (build from different revision or whatnot). Much depends on the quality of the project, the discipline put into the build process and care to avoid environment specific configuration that is not part of the source. The larger and older is the project, the less chances are you are able to recompile it successfully using only src jar.
A sane man's approach. You should have your build scripts, readmes, tutorials, etc. Except, of course, if we are talking some obscure company internal project with zero effort put in its maintenance. Surely, there are the same issues as before: not all projects are rebuilt easily on any environment. There may be steps upon steps required for your workstation to be configured as expected. Hopefully, self-respecting open-source java projects are easy to build, but again - not a given - not all project are open-source, not all are self-respecting.
Important note: When checking out the git repo of your dependency - you must also make sure that you are using correct revision. If the project is maintained with respect for git tags/branches naming convention - you are in luck. Not a given by any means.
All the above is enough to discourage any attempts to automatically decompose dependencies to compilable units by your IDE, and all the burden is put into you. So let's assume the best - our dependency is a simple, self-contained java application that is easily built using simple mvn clean install. You have it checked out in a separate project in your IDE. You identified correct git revision that matches version your project depends on.
Now let's apply your little change and test it. First thing you want to do is change pom.xml of your project to use a made up version of your dependency. It should be a -SNAPSHOT version for clarity and tidiness. You may of course build your modified dependency with real release version - but please be wary of how maven manages dependencies. If you install version 1.0 yourself - it stays in your local repo forever. You will forget about it, and will be using your fake 1.0 version when building all other dependent projects unless you manually locate and remove it from repo. So stick to 1.1-SNAPSHOT.
Now every time you need to apply a small fix to your dependency, execute mvn clean install in its repo, then make sure your actual project depends on the correct new SNAPSHOT version, execute your maven clean install and that's it.
Note that all this has very little to do with Intellij. You are not expected to modify any library paths, advanced project settings, or links to jars. Stick to modifying pom.xml and you are set.

How to resolve requirement: Import-Package:

The scope of this question applies after you have created an RCP app in eclipse following Vogella's tutorial linked below. This assumes your feature, product, and father project are created. In this state the feature is delegated the task of building, therefore all dependencies need to be resolved in the feature build.properties file.
This question addresses when the missing dependency needs to be installed, i.e. is downloaded manually because the missing dependency is not on the class path. The class path determines what plugins are available in the feature/included-plugins tab. The plugins listed in the feature/included tab can be added as plugins for dependencies to your plugin. This list gets appended to your feature.xml file which gets linked to your build.properties file! See Solution below.
Eclipse nomenclature interchanges the ideas of plugins=dependencies and treats them the same. We know this by the names of the tabs.
The intent of this question is aimed at using existing Eclipse capability to develop an RCP application that uses objects from a third party plugin to create a custom workflow.
This error is thrown because my RCP app third party plugin requires this dependency which was not included in Eclipse ICE nor the plugin itself.
The first thing I tried was to install the plugin directly from the Eclipse Marketplace.
The string org.apache.commons.beanutils returned nothing so I went to apache and downloaded the plugin manually.
I then researched how to install a plugin in Eclipse manually.
I've learned not to simply drop the plugin into the Eclipse/dropins folder, which does nothing.
I've learned that this advice is lacking probably due to age of post.
I've learned when Maven is configured correctly, all the dependencies can automatically be resolved.
https://www.eclipse.org/forums/index.php/t/813199/
This says plugin dependencies are resolved by looking at four files.
"The plug-in definition, the product file, the run configurations and the target definition."
The plug-in definition I'm not sure what that is other than the plugin.xml file. The product file has been configured to launch the third party plugin. I've learned the run-configuration has a list of plugins and the third party plugin is not listed there.
I've learned that the target definition should be created in the parent project of your product project.
Create a target definition by highlighting your father project->Right click-> new-> Other-> Target Definition. During creation select "Use workspace configuration." The path to your downloaded plugin was added to this Location.
After the Target is created, Navigate to the content tab and select Manage Using: Features
This reduces the number of possible dependencies to only the ones needed to run.
You should now see the dependency checked in the list.
Creating the target resolved the other twenty or so dependency errors but the one under the title still throws an error.
I've learned that the product file is the file that calls the third party plugin in runtime.
The RCP app launches, but I cannot import the third party plugin in the bound classes created using this tutorial, to be used to obtain objects programmatically.
http://www.vogella.com/tutorials/EclipseRCP/article.html
I have a shell of a program running and just need to implement the classes for each window with the objects I can get from a third party plugin import.
Thanks,
(Solution)
Thanks Brian for resetting my thinking which led me to learn about Eclipse a little more to figure this out.
The main problem is an external .jar is identified as the missing Import-Package. Mine was org.apache.commons.beanutils. You must go to the parent website and download the library. In this case apache's website. There is probably a better way to do this by repo. I'm hoping I can export the product with all the required dependencies :p
I may be able to skip a step or two here, but these were my working steps.
Get .jar into Eclipse parent project. Right click the parent and select New->Folder->Name it Lib->Finish. Right click Lib->Import->File System->Navigate to .jar. Highlight the included .jars->Right Click->Build Path->Add to the Build Path.
Add the missing .jar to your Ant class path. Ant is used to build PDE apps using OSGi. See the Eclipse Help for an explanation. This will allow your missing jar to become visable in the feature project included-plugins tab.
Window->Preferences->Ant->Runtime->ClassPath Tab->Add jar->Navigate to missing jar
Create a target definition as described above in your parent project and add your missing .jar to the target and set your target active.
If target exists, In Locations widget window->Click Add->Directory->Navigate to missing .jar.->Next-> Verify plugins are recognized in window->Finish. Click Set as Target Platform in upper right corner.
Open feature.xml in your feature child project. ->Click Add->Navigate to your added plugin->Click Ok
Save All - Launch product
Now onto the next dependency!
Sounds like you're confusing an Eclipse plugin with a jar dependency for your project. it sounds like your project needs a jar (the beanutils jar from Apache) . Depending on if your project uses Maven or ant (or something else) the way to add it to your project varies. Try googling something like "adding a jar in eclipse for a X build" where X is the tool used for your build (ant, maven, etc). No matter what you use, the end goal will be for that jar to show up the java Build path->Libraries for your project in Eclipse.
it seems to me that u need a better understanding of how dependencies are managed in OSGI/eclipse, therefore i concur with BrianPipa.
beware: that subject is quite large and not easy to understand and is way too large to be explained here. but be not afraid, google is ur friend:
a few pointers on research topics:
the relation ship of bundle/plugin and jars
how is code contained in a plugin exported (aka make visible) to other plugins so they can use it AND what needs to be done so that the using plugin (ie. declare that usage-dependency)?
how are feature related to plugins?
how are products related to plugins and features?
what is a target platform ?
and how do i define it and what does it need to include ?
how do i set it ?

No source code is available for type com.google.gwt.ajaxloader.client.AjaxLoader;

I am migrating an project someone else built to newer packages and I have traced the root of my errors to this
No source code is available for type com.google.gwt.ajaxloader.client.AjaxLoader; did you forget to inherit a required module?
I am new to GWT and not really sure how it works 100% under the hood so I am having trouble applying solutions to similar posts to solve this error.
go to Maven Repository and get gwt-ajaxloader.jar - it contains both .java and .class files
save the jar to war/WEB-INF/lib folder in your project
right-click on the file in Project Explorer (I assume you use Eclipse), select Build Path -> Add to Build Path
enjoy ;)
GWT needs source code as opposed to .class files to do its work.
So any references you might have from your client code towards any jars, etc, need to also include source code.
In your case, you either need the source of com.google.gwt.ajaxloader.client.AjaxLoader, or remove any references towards the mentioned class, from your GWT code.

How can i open an Akka project using eclipse?

i am trying to create a simple hello-akka project using the typesafe activator. I have everything working and the project even runs in the typesafe tab. I clicked on create eclipse project, and some files are added to my directory but i cannot figure out how to open them and run the file in eclipse!
These are the files i currently have in the directory:
.sbtserver
project
src
target
gitignore
(GITIGNORE FILE?)
activator.bat and activator.jar
build.sbt
In another workspace i tried creating my own scala project, by adding akka-actor.jar to the libary but i get the following error :
Description Resource Path Location Type
missing or invalid dependency detected while loading class file 'ActorSystem.class'. Could not access term typesafe in package com, because it (or its dependencies) are missing. Check your build definition for missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.) A full rebuild may help if 'ActorSystem.class' was compiled against an incompatible version of com. tst Unknown Scala Problem
Any help or suggestions would be greatly appreciated!
There are quite a few dependencies you'll need to find and add if you're determined to make this work -- a scala-library, for example. It's better to find a way to integrate your build with your IDE if you can -- this will allow the IDE to find dependencies the same way the build does -- and in this case, the build system is SBT.
The easiest path forward may be to download ScalaIDE, which is a Scala specific package for Eclipse. This should come ready to go with support for SBT projects. Most Actor/Scala devs I know use IntelliJ or ScalaIDE.
Another option would be to use the SBT plugin for Eclipse, but in my experience it tends to be unreliable, changing with far less frequency than the IDE itself. If you install it and it doesn't look like it's working, you're probably right.
Finally, you can ditch SBT for Gradle or Maven and then use the Gradle or Maven plugins for Eclipse. If you have either of those in your shop already this is likely something you will need to do down the road, anyway. SBT is a good build system but nowhere near as feature rich as Gradle or ubiquitous as Maven.

Configure Eclipse workspace automatically

I have a eclipse workspace which constitutes of 15 different java projects . To configure the eclipse workspace , every time I need to add the java projects manually and add the dependency and refrences in the java build path.
Adding all the projects and resolving dependency every time becomes a manual and redundant task. I explored on the .classpath inside the every projects which stores the dependency and refrences information.
I would like to automate this redundant process.
Have any one tried doing that , any inputs will be helpful.
I don't need to add same project more than once , but often need to create a new eclipse workspace with new code changes and delivery (I can't take some of the changes in the current work space).In simple terms for e.g if some one need to create eclipse workspace again and again , or multiple people need to create the same workspace for their work . How can we reduce that manual effort?
I am still a little unsure about your motivations but I am going to assume that by new code changes and delivery you mean a different revision/branch of the same code base. For this purpose and for many other reasons, if you are not using source control like SVN or Git, look into it. These tools are priceless and also free.
Eclipse
I don't think this is technically part of your question but I wanted to add it for completeness. If you're implementing the techniques below, it is also handy to have a 'fully loaded eclipse'. I keep a 'fully loaded eclipse' on a network drive somewhere with some plugins pre-loaded so that new additions to the team don't have to download/install the plugins. It's not hard to do since eclipse doesn't need to be 'installed'. You can just copy the eclipse folder to where you want it and run it. Personally I like to include plugins for source control, code style, code coverage and metrics but you should include anything that you use consistently in your project.
The Workspace
To copy an existing workspace (not including any projects, I'll get to that later) all you have to do is copy the .metadata folder from an existing workspace folder to an empty folder that will be your new workspace folder. When you start up eclipse simply choose the new workspace folder and you will have all the same preferences as you had in the other workspace.
I have used this technique before so that when people join a project they can take a copy of a 'clean workspace' I keep on a network drive somewhere that helps them get up and running quickly. Preferably, this 'clean workspace' should not have any preferences that are only personal preferences like having the perspectives setup just the way you like it but should only have preferences like Ant global properties, compiler compliance level, pre-made commonly-used external tool and run configurations etc.
Projects
For the projects themselves, I would recommend checking them into source control including the eclipse .project and .classpath files. The SVN plugin (subclipse) makes it very easy to do this. Then when someone joins your project, all they have to do is check them out as projects in their new 'clean workspace' which is also very easy to do. Since the project you're checking-out already has the .project and .classpath files, all of the dependencies are already setup! Just make sure that all the jars and any other dependencies are checked-in with the projects.
Workspace Setup Procedure
Take a copy of the 'fully loaded eclipse'.
Take a copy of the 'clean workspace'.
Check out the projects into that workspace.
That's it! Your new recruit should be ready to go!
Multiple Code Branches
Now, if I was right to assume that by new code changes and delivery you mean a different branch of the same code base, creating a workspace for a different branch as easy as following the same steps but checking out the required revision or branch instead of the latest version from the trunk. If you don't quite understand what I mean by that, read up on source control.
Cudos
Good on you for taking the time to do this, I have been in projects where it can literally take a day to get setup...
Maybe little late, but stuck into the same problem and found a tool in eclipse marketplace that helps to manage setting up and launching eclipse all time for different branches, new developers or other reasons.
The tool is called yatta.
With this, one can create profiles which can be based on their current running eclipse with all the tools, plugins, workspace, CSM repos and what not.
This profiles can be exported to yatta profile hub which can be public or private and later shared with different developers and can be imported and launched.
You don't say whether you're using a build tool other than Eclipse, but if not you should.
Eclipse is able to parse Ant files to discover the source directories and libraries. And Maven and Gradle can both generate Eclipse project files for you to import.
As a longer-term benefit, using a build tool means that you can easily build and deploy your projects without any need for Eclipse. And it will be easier for new team members to work on the projects, as they won't need to figure out all the dependencies.
If you don't already have people with expertise, I would recommend Maven. It's easy to set up a basic Java build script, and its dependency management features are IMO better than the alternatives. It will, however, force you into its way of doing things, particularly wrt source tree layout.
You should really look into build tools like Maven, Ant, .... Those can generate needed classpath variables for you automatically and can do many more things as well
If you're checking out the projects from CVS / SVN in Eclipse, then it's possible to create a Team Project Set. This is essentially an XML file that will contain a list of projects and their source repository path
It can be exported via File | Export | Team | Team Project Set, and imported into another workspace via File | Import | Team | Team Project Set
There's more information on this feature at this link on Javalobby
Using vagrant it is quite easy to automate setting up an entire desktop development environment.
See the answer I provided to a similar question here, which has links to scripts that automate checking out maven projects, creating an eclipse workspace and importing the projects.

Categories