Intellij import existing resource into package - eclipse

I'm following a Udemy course that uses Eclipse for Scala. Using Eclipse, he creates a package, then right-clicks on that package, selects Import, then General, then FileSystem and selects an existing resource that he provides in the course.
I'd like to know how to do this in Intellij. I created a package but see no way to import an existing resource into it.
Many thanks.

You either configure content root in the existing module or add a new module with the source roots, then make your main module depend on it.
IntelliJ IDEA will not copy the files from some other location, so you have two options:
set up a module with the content roots for the existing location with the sources
copy files to the existing module source root using your favorite file manager.

Related

How to import ATG CRS module in eclipse and customize

I am new to ATG and i installed ATG CRS 11.2 using CIM and it is installed properly and i am able to access the site but i want to import the CRS module in eclipse and customize the existing code for my learning purpose.
I tried the ways given on net, install atg plugin and trying to import but it is not importing.
Please explain the steps to do same.
Thanks
The Oracle A-Team have an article Building Oracle ATG Commerce With Maven. They have created a sample github project which uses CRS 11.2 as the basis for the project. You should be able to import this as a Maven project within Eclipse.
Create a new Java Project in Eclipse
Using windows browser, go to the location where your Java Project is created.
Open the Java Project folder, you will find .classpath and .project files there.
Now, go to your ATG_ROOT folder, and find the folder CommerceReferenceStore/Store
Copy-paste your .project and .classpath files here.
Edit the .project file and replace the project name by CommerceReferenceStore.Store.
CRS also has some other (nested) modules. Do the same for the nested modules you want to import in eclipse.
Re-open eclipse, Go to File -> Import -> Other -> Existing Projects into your workspace.
Browse to your ATG_ROOT directory and select the Store folder
Check on "Search for Nested Projects"
It will populate a list of all the projects, which you can now import.
For customizing CRS, it is not recommended to modify the existing CRS
code. You can create a new module, and layer it on top of CRS to
customize it. For more details on creating a new module above CRS, and
doing an assemble-deploy via CIM, you can follow this article provided
below. It has 3 small parts which can get your task done!
Here is the article:
http://learnoracleatg.blogspot.in/2016/12/create-and-deploy-new-atg-module-on-local-from-scratch-part-1.html

How can I import plugin projects from my workspace without specifying them?

I am developing an scripting environment for EMF and need to import the model plugin so that my script is able to use classes generated by the model, but in order to do that I need to explicitly add the plugin to my imports.
Can I do that automatically? Like adding all workspace plugins to my imports at runtime?
You can use DynamicImport-Package: * attribute in the bundle manifest to make all exported packages visible.
Note that packages imported via DynamicImport-Package are resolved every time a class from the package is needed. Consider selective dynamic import DynamicImport-Package: *;dynamic=mymodel or buddy policy as better alternatives.

Getting imported files from sample java program to new program

I'm trying to make a small java program revolving around Google Calendars. I've never worked with java before but I was able to get Google's sample code working. In Eclipse, I simply used Import -> Maven, and then made some small changes to the code so that it worked on my Calendar.
Ok, great, now I want to write my own code. I started a new project and imported the Google Calendar API. At the very beginning, there are several import actions:
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
.
.
.
It turns out that I'm missing the second and third files. How do I find these files and how to do import them to the new project?
Please note: I ultimately don't want to rely on importing the Google Calendar API or anything similar, as I will be using another non-java program to run and control this one.
Here's what I tried:
I go back to the sample code, expand Maven Dependencies and find:
google-oauth-client-jetty-1.19.0.jar
google-oauth-client-java6-1.19.0.jar
I see that these files are in:
C:\******\.m2\repository\com\google\oauth-client\google-oauth-client-jetty\1.19.0
C:\******\.m2\repository\com\google\oauth-client\google-oauth-client-java6\1.19.0
I tried to add these with Import -> Java EE -> App Client JAR file
Didn't work, do I need to change the file name or import name? Maybe these aren't the correct files anyway.
I also tried to add these by creating a lib folder in my project folder and add the JAR files directly there.
I guess from your question your project is just an Eclipse project rather than a Maven project. Obviously Maven automatically add the required jars of the dependencies stated in pom.xml for example google-oauth-client-java6-1.19.0.jar is a dependency of google-oauth-client-jetty-1.19.0.jar.
To add external jar to your project in Eclipse you need to select the project then from the Project menu select Properties. On the properties popup click on the Java Build Path, you have two options depending where the jars are stored, if you are referring to the maven .m2 directory then choose 'Add External Jars' otherwise if you added them to a lib folder in the project choose Add Jars

How to set reference to the folder which contains multiple jar files?

My environment:
Netbean 6.9.1
Glassfish 3.0.1
Windows 7
Goal:
When my coworkers opens the Netbean Project, the library is already referenced without them manually create library, adding jars into it and reference it.
Detail:
I created Netbean project and the project has reference to few jar files in the folder.
Currently whoever opens the project for the first time, they have to manually create library and refer it to the project.
My project location:
C:\Users\masatosan\Desktop\myProject\myApp
My library location:
C:\Users\masatosan\Desktop\myProject\lib\myLib
The myLib folder contains:
some1.jar
some2.jar
some3.jar
I can achieve my goal if I create reference to individual jar file by defining to project.properties file like below: (creating reference to sqljdbc4.jar)
file.reference.sqljdbc4.jar=../lib/sqljdbc4.jar
javac.classpath=\
${libs.restlib_gfv3ee6.classpath}:\
${file.reference.sqljdbc4.jar}:
But my case is different since I have 3 jars in the myLib folder and wanting to reference them all.
Is it possible to reference all jars in myLib folder?
Please let me know if you need more clarification.
I'm sorry, but it doesn't work that way. When you create a project, you have to add the jar files individually.
However, if you put your lib folder under your project, netbeans will refer to them via relative paths. Then when you share the project (lib directory included), netbeans will be able to automatically find the jar files when the next person uses the project. That way you only have to add jar files once.
Short of using a dependency management tool like maven (which Netbeans has good support for), this is really the best solution. It uses a bit more disk space (obviously), but that's never been a huge issue for me.
I figured how so let me share.
Tool --> Library then library window pop up.
Create library called "MyLib" which contains multiple jars.
Add "MyLib" to your project. This change will be written to project.properties file under nbproject folder.
project.properties file indicates the classpath of lib reference you just added.
It should look like something below
javac.classpath=\
${libs.Excella.classpath}:\
${libs.MyLib.classpath}
Now someone else opens the project from different machine and she just needs to do step#1 and #2, which is to create library with same library name i.e. "MyLib"
I think this is what Bill was saying originally but thought it would be helpful to give step by step instructions since I finally figured .... after long time :D

How to import user libraries programmatically from a file

I have "myUserLib.userlibraries" file with all the required user libraries defined. As part of my plug-in that i developed (this will create web projects and required settings), i want to import this file to the projects created by the plug-in.
Is there any programatic way to import libraries from a file?
If you are developing a plugin to add these libraries to project classpath, I recommend that you consider writing a custom classpath container rather than re-using the user libraries facility. If you write a custom container, project classpath would include id of your container and JDT will query your code at runtime to get the actual list of classpath entries.
This will save you from having to store and maintain the contents of your library in workspace preferences, as you would have to do if you took the user library approach.
See org.eclipse.jdt.core.IClasspathContainer class.
Finally i got this worked the way i want. I am now able to programmatically upload the userlibraries into workspace preferences from "myuserlibs.userlibraries" file. I used following eclipse plugins classes.
org.eclipse.jdt.internal.core.UserLibrary.class
org.eclipse.jdt.internal.core.UserLibraryManager.class
org.eclipse.jdt.internal.core.UserLibraryClasspathContainer.class
org.eclipse.jdt.internal.core.UserLibraryClasspathContainerInitializer.class
These classes have bunch of methods to achieve this task.
Once they got uploaded in to preferences, i am also able to programmatically add required user library entries into a respective projects (created by my plugin). Because i have around 8 web projects in my workspace and all of them required different set of user libraries in their classpath container.