Add external java files(*.java file, not a jar file) to project in Intellij - intellij-idea

I have many java files on one directory and I want to use it in my Intellij project. But I don't want to copy the java files to my project each time when I start a new project.
I know I can use reference in Visual Studio and Xcode.
I'm wondering whether I can do it in Intellij(14 CE)

Project Structure -> Modules -> Add Content Root -> (select directory containing external source files).
IntelliJ should detect the content as a Source Folder. If it doesn't detect it correctly, you can select it in the right-hand-side of Project Structure, and Mark as: (Sources).

Related

How to create an empty JavaFX project in IntelliJ

Every time I create a new JavaFX project in IntelliJ it loads a simple HelloWorld project in it. How can I make it empty instead (without the need to delete those .java files every time)? Also how can I choose to create the project without a building system (as you can see in the picture, I'm always forced to create the project with Maven or Gradle)
When creating the new project, choose "Java" instead of "JavaFX".
A JavaFX application is just a Java application, so if you don't want the additional things which IntelliJ is doing when you choose to create a JavaFX project (e.g. supplying example code and associating with a build system like Maven or Gradle), you can just choose a basic Java application project from the wizard and it won't do those other things.
See the section in openjfx.io documentation titled "JavaFX and IntelliJ IDEA" for other steps you need to take:
Set the project JDK
File -> Project Structure -> Project
Create a JavaFX library in Idea
File -> Project Structure -> Libraries
Point to the lib folder of the JavaFX SDK.
Add VM options for the module path
Run -> Edit Configurations...
--module-path /path/to/javafx-sdk-15.0.1/lib --add-modules javafx.controls,javafx.fxml
For windows use quotes around the path and \ rather than /.
Run the project
Run -> Run...
You might also need to take the actions identified in the accepted answer to:
How to convert a normal java project in intellij into a JavaFx project
But that answer was written a while back and setting the resource copy configuration to include JavaFX fxml and css files might not be needed anymore.
Now, you might think that is annoying amount of things to do, and I might agree with you.

Command line generation of IntelliJ IDEA project files?

I prefer having one IDEA project per task I'm working on. If it's a Gradle project, I can run gradlew idea to generate the project files then rename them to be indicative of the task I'm working on (so that when re-opening from IDEA a project, it's obvious what the task is and IDEA is able to list several tasks for the same Gradle project). This works well enough if it's a Gradle project, but if it's not, I'm left with using the IDEA GUI to open the project by pointing to the working directory. Is there a command-line way to generate the IDEA project files so I can rename them prior to using the GUI? Being able to do this would also obviate the need for using gradlew idea for this purpose.
Using the GUI, create the project by pointing it to the build.gradle file or project root directory. Once the project is created:
click the File menu
click the Project Structure menu item
change the Project name text value

How to make XamarinStudio generate object files into a seperate directory?

Let's take this one by example. I'm developing on linux and using XamarinStudio for all of my .NET projects. I like it more than having VisualStudio running in the virtual machine. I have a solution that has several projects in it, that looks like this:
/Solution
/Solution/Project1 -> project number 1
/Solution/Project2 -> project number 2
/Solution/Project3 -> project number 3
/Solution/Output -> output folder for all projects
/Solution/Temp -> temporary files for all projects
I'm able to set the output directory for all projects, but I don't know how to set projects to generate temporary files to the Temp folder. Right now temporary files are generated into /Solution/ProjectX/obj/x86/Debug/ and /Solution/ProjectX/obj/x86/Debug/. How can I change it? I couldn't find the way to set it in the project/solution properties.
If you are using MSBuild to build your projects from within Xamarin Studio then you can use the IntermediateOutputPath element in the project file (.csproj) to override the default directory where obj files are stored.
<IntermediateOutputPath>..\Temp\ProjectX\obj\$(Configuration)\</IntermediateOutputPath>
You can change where obj files are saved by editing the project file (.csproj) in a text editor and adding the IntermediateOutputPath so it points to your temp directory. You will probably want to have different directories for each project.
I tried this with Xamarin Studio 5.7 with Mono 3.12 on the Mac and it seems to work. This should also work with Visual Studio.

Adding Jar files to IntellijIdea classpath

I have created a new Intellij project. But I can't use the third party jars in my project. I have the jars in a directory structure as follows:
repository/commons-logging/commons-logging-1.0.4.jar
repository/commons-lang/commons-lang-2.1.jar
etc.
I want to add them just by pointing to the repository directory, but couldn't find any ways to add them.
But when I am using classes or API from that jars, the editor can't resolve the classes.
I have tried from Project Structure but can't configure it.
Go to File-> Project Structure-> Libraries and click green "+" to add the directory folder that has the JARs to CLASSPATH. Everything in that folder will be added to CLASSPATH.
Update:
It's 2018. It's a better idea to use a dependency manager like Maven and externalize your dependencies. Don't add JAR files to your project in a /lib folder anymore.
If, as I just encountered, you happen to have a jar file listed in the Project Structures->Libraries that is not in your classpath, the correct answer can be found by following the link given by #CrazyCoder above: Look here http://www.jetbrains.com/idea/webhelp/configuring-module-dependencies-and-libraries.html
This says that to add the jar file as a module dependency within the Project Structure dialog:
Open Project Structure
Select Modules, then click on the module for which you want the dependency
Choose the Dependencies tab
Click the '+' at the bottom of the page and choose the appropriate way to connect to the library file. If the jar file is already listed in Libraries, then select 'Library'.
On the Mac version I was getting the error when trying to run JSON-Clojure.json.clj, which is the script to export a database table to JSON. To get it to work I had to download the latest Clojure JAR from http://clojure.org/ and then right-click on PHPStorm app in the Finder and "Show Package Contents". Then go to Contents in there. Then open the lib folder, and see a bunch of .jar files. Copy the clojure-1.8.0.jar file from the unzipped archive I downloaded from clojure.org into the aforementioned lib folder inside the PHPStorm.app/Contents/lib. Restart the app. Now it freaking works.
EDIT: You also have to put the JSR-223 script engine into PHPStorm.app/Contents/lib. It can be built from https://github.com/ato/clojure-jsr223 or downloaded from https://www.dropbox.com/s/jg7s0c41t5ceu7o/clojure-jsr223-1.5.1.jar?dl=0 .

When deploying Xtext, how to integrate with Eclipse via plugin?

I have finished a beta of my Xtext and Xtend project. Now I want to integrate it with an Eclipse. Using this new Eclipse I want to be able to choose "New 'mydsl' project", then in this new project I want to have a .jar referenced by default. Also an empty file of mydsl. If it is possible, get rid of adding Xtext nature to project .
There are several non-trivial processes for this question:
To be able to choose "New 'yourDSL' project", you will have to implement your own project wizard. That is, in your plugin.xml file you have to contribute to the extension point "org.eclipse.ui.newWizards" and create a class that must implement the INewWizard interface, you can do so by extending the Wizard class.
That wizard, in the performFinish() task, should create a IJavaProject programatically where you can specify the Natures that you want. You also will have to specify the source and output folders, and configure the classpath (adding the classpath entries) as well. This link goes on more detail on how to create the project. http://www.pushing-pixels.org/2008/11/18/extending-eclipse-creating-a-java-project-without-displaying-a-wizard.html
In the previous step (#2), when creating your custom project, you can add packages, folders, files, so you can add your empty .mydsl files.
Now the trickiest part. To have the .jar file referenced by default there are several approaches. The easiest one is if you know the .jar path beforehand, you can add the reference by adding (in step #2) a classpath entry of type CPE_LIBRARY that point to that .jar file, but again you need to know the path somehow. In my case I didn't know the path because my .jar file was a library exported as plugin, so I ended up by implementing an IClasspathContainer that looks up for my plugin-library (.jar file) among the installed plugins. You can look up for your a plugin by doing:
Bundle bundle = Platform.getBundle("com.my.libraryPlugin");
File bundleFile = FileLocator.getBundleFile(bundle);
... and then, in step #2 what I add is a classpath entry of type CPE_CONTAINER:
JavaCore.newContainerEntry("MY_CONTAINER");
You can read more about IClasspathContainer here: http://www.ibm.com/developerworks/opensource/tutorials/os-eclipse-classpath/section2.html
5- You probably know how to do this already. The last step is to export your DSL plugins and copy them in the "plugins" folder in the Eclipse installation. To export the plugins: Select the projects -> Right-click -> Export -> Plug-in Development -> Deployable plug-ins and fragments...