How to mark package as a resource folder? - intellij-idea

I have a dir structure for Intellij 12:
...
...test
- java
- com.mycompany.myproject
- package1 (contains code, etc,.)
- resourcePackage (want to contain .json files but can't mark as a resource)
- myOtherJunk.json
- o o o
- resources
- aResource.json
The thing is if I right click on my package name (com.mycompany.myproject) I can only add packages and not directories (like that of an existing resource folder).
However, I don't want to use that existing resource folder for the .json files that I'm going to read into per my test class.
So, I need something to support:
// this already works for the resources directory per the .json file but doesn't for the
// myOtherJunk.json per the resourcePackage.
InputStream is = MyClassTest.class.getResourceAsStream("aResource.json");

This can be solved in several ways. An example of a good approach would be the following folder structure:
src
main
java
resources
test
java
resources
When this is done, you put all you java classes under src/main/java/com.mycompany package and any resources under /src/main/resources/com/mycompany folder.
To link them together, go to the project properties, and find the Path tab. Mark the src/main/java and src/main/resources as source folders. (see the screen-shot attached)
If you link them together, you'll be able to use getResourceAsStream() method.
If you wonder why you should use the following folder structure - this is standard maven way of keeping things clean and tidy.

Directories Creation
Intellij creates directories when you ask her to create package. It is not an error.
If you create package "com", it will create the dir "com", and if you create a source file there, it will think that the file is in the package "com".
If you create package "com.next.pack", it will create three nested dirs "com", then "next", then "pack", and if you create a source file there, it will think that the file is in the package "com.next.pack".
Directories Structures
Only the path under the source root is taken as a package. Any directory(ies) can be set as a source root(s).
Resources roots
Make practically any structure of directories. Somewhere in it there is the root dir of resources. Right-click it and Mark Directory As ... Resources Root.
Notice, the same method can be used for the directories structures for tests, test classes, and test resources. Look here.

Please use #ContextConfiguration annotation to load the resource files. Please see below example.
#ContextConfiguration( { "/app-config.xml", "/test-data-access-config.xml",application-test.yml })

Related

how to create a task that uses a text file in IntelliJ eduTools

I am trying to create a task that needs to read from a file in IntelliJ EduTools.
I tried creating a directory at the root of the course and marked it as a resources, I tried putting the actual file in the src component of the Task. I tried a number of locations for the resource file.
Here's what I got. Once I created a resource file at the top level of the project, the task was able to work. However, the tests were not able to find the file. (I then tried creating a test resource directory in many locations without success).
Where should I place resource files for Tasks and Tests to run in IntelliJ Edu Tools?
You should put the files for tasks into the task directory and files for tests into the tests directory. Path to file should be defined like this:
./filename.extension - for task files
./tests/filename.extension - for test files

Something strange with Project Paths in IntelliJ 14.1.4

So, something has started to act weird in my intelliJ project. I even tried removing the iml and .idea data, to no avail.
I go to Project Structure. There, I have a content root. Withing, I have three folders - one for my jar (and jni lib), one for Samples and one for Tools (just tools written to use the jar). The jar, Samples and Tools are marked blue (sources).
In the jar folder, I have my source tree (com\company\projectname\XXX), a lib folder, a folder for my JNI lib and a folder I created call 'junit', which is the focus of this question. It is marked in Project Structure in green (Tests).
Within, I have a folder structure eerily similar to my code: com\company\projectname\junit.
When I open a file in junit\com\company\xxx\junit, I have a big red underline under my package com.company.xxx.junit; line which tells me: "Package name 'com.company.xxx.junit' does not correspond to the file path 'junit.com.company.xxx.junit'.
I was under the impression that marking a folder as 'Tests' would instruct the IDE to use that as a "parent" folder, if you will, eliminating the need to prepend another folder name.
How can I separate the code from unit tests and in fact, create two junit test suites (one is for internal use, the other is a 'skeleton' for distribution), park them under one "umbrella" folder and NOT have to prepend the package names with that folder name?
Update: Project structure:
Based on your screen shot, the issue is that the junit directory is a subdirectory of another source directory, namely MyProvider. A source directory (whether a "production" source or a unit test source directory) cannot be a subdirectory of another source directory.
You need to either:
move the junit directory out of MyProvider so it is a sibling directory, or
unmark MyProvider as a source directory, create a main (or some such directory) in MyProvider, mark it as a source directory, and then move the com directory/package into main.
Option 2 would be the preferred way to deal with this as it follows a very common directory structure standard.
UPDATE (Following comment from OP)
Here's a couple of screenshot showing the configuration you desire:
I removed the .IdeaIC15 folder and started over. Working for now. Something must have gotten confused in the config, either as part of the update, or in the course of operation. I have taken a backup copy as it is now, so if this happens again, I will have something to check.

What is the file structure of the Share Webscript extensions for Alfresco 4.0.3+

I've been reading David Drapers' blog on the new feature - the extension of share webscripts, but I didn't find any working examples. What is the file naming and structure convention?
From what I gather, I have a module configuration file, and I don't know how to name it or where to put it (share/WEB-INF/classes/alfresco?)
Also, I understood that my custom client side resources (.js and .css files) go to META-INF/custom-dashlet/extension/ in the JAR file. Is this correct? Finally, the *.get.js and *.get.html.ftl go to webscripts/com/mycompany/mypackage/*?
So I have now:
*share/WEB-INF/lib/mypackage.jar*
and in it:
*META-INF/mypackage/extension/myfile.js
webscripts/com/mycompany/mypackage/myfile.get.js
webscripts/com/mycompany/mypackage/myfile.get.html.ftl
*
and the
*share/WEB-INF/classes/alfresco/something.xml*
This question was also posted to the Alfresco forums here: https://forums.alfresco.com/en/viewtopic.php?f=48&t=46438
The answer provided was as follows:
An extension module a Surf configuration object so you should place XML files containing module configuration in any of the locations where Surf config gets picked up... e.g. <web-server>/webapps/share/WEB-INF/classes/alfresco/site-data (there are lots of places where Surf configuration gets picked up, but alfresco/site-data on the classpath is the most common). Extension config files should be placed in the extensions folder within the directory. So you could place an extension config file in: alfresco/site-data/extensions or alfresco/web-extension/site-data/extensions, for example.
You could create a JAR file containing this folder structure. Everything that the extension refers to (e.g. WebScripts, other Surf config objects such as Pages, Template-Instances, Components, etc) should just be placed in their normal location. These can also be built into a JAR file.
If you want to access resources (e.g. CSS, images, JS) from a JAR file then place them in the META-INF folder of the JAR. You should place your JAR file in the <web-server>/webapps/share/WEB-INF/lib directory (obviously your server will need to be restarted to pick up new JAR contents).
WebScripts should be in (on the classpath):
alfresco/site-webscripts
alfresco/web-extension/site-webscripts
webscripts
You can also configure other locations in the Surf configuration from which to load Surf config objects/WebScripts. It's pretty much endlessly customizable but you should probably just stick to the default locations configured for Share.

How to add non-source folders to IntelliJ IDEA project

Recently set up a multi module project in IntelliJ with the following structure:
/module1
/module2
/web-module
/sql
/lib
/a few more folders
I set up module1+2 and web-module as modules in IntelliJ so those show up, but how do you make the sql and lib folder show up in the project panel? They should be included in VCS as well, but IntelliJ ignores them. How do you add folders outside modules to a project?
Screenshot of project and explorer view:
This is not a strict answer to the question, but it worked for me so I'm posting, perhaps someone will find this useful.
If you want to add an arbitrary folder to your project (even from some different location than your projects), just add it as a module. You needn't worry about the type so much e.g. I needed to add a folder with some SQL scripts, I added it as a Java module and it's nicely visible in IntelliJ even though it has no maven structure or Java sources.
This is how to do it:
File > Project Structure > Modules
Add > New Module > ... (e.g. Java Module)
In the new module settings mark the subfolders that you want to see as 'Sources'
VoilĂ ! :)
This is something that I typically see when creating a project from existing modules. All the modules will show in the project but not the other project related directories. These directories might be, configuration files, environment scripts or bundles of SQL scripts that don't fit neatly into an Intellij module type.
To show the rest of the project source files and directories, I create a parent module from the project root.
File->Project Structure->Modules
Create a new module using the + sign. The new module could be any type (I use java).
On the Next screen set the Content root and Module file location to the Project's root folder.
Select Finish
All of your other modules should now be submodules of the root, and your other project files should now show up.
Add and remove content roots
To add a new content root:
Go to File | Project Structure, or press Ctrl+Shift+Alt+S.
Select Modules under the Project Settings section.
Select the necessary module, and then open the Sources tab in the right-hand part of the dialog.
Click Add Content Root.
Specify the folder that you want to add as a new content root, and click OK.
source: https://www.jetbrains.com/help/idea/creating-and-managing-modules.html
I used File -> New -> Module from Existing Sources...
Then I simply select the folder and add it.
In Project view mode all directories (except the ignored ones from the settings) should show up. Of course the base folder for your multi-project has to be the folder above module1.
EDIT:
Your project should look like this (project view tree):
MY_PROJECT_ROOT (~/the/folder/to/your/project)
|- /module1
|- /module2
|- /web-module
And in this case, you should definitely see the other folders. I got a sample project set up where this is working.
EDIT 2:
From your screenshot, I assume you are missing the root directory (the project root is not as you expected). I added another screenshot. There should be a single root folder for your 3 modules. This one is missing at your screenshot. You have 3 separate folders with no common root folder. On MacOs, the project root is displayed in the window title. In my case it points to ~/devel/sandbox.
I guess you should try to create a new project in for that trunk folder. From the scratch. Then add the existing modules and you should be fine?!

How can I write into a file within an Eclipse bundle?

I have an xml configuration file located into my plugin resources. I want to update this file whenever in the plugin happens some event. I found some methods to find and read the contents of a file located my plugin classpath, but I'm looking for a way to write into such a file.
Is there any way?
Many thanks.
That location (the install directory) is intended to be read-only since it may be shared in a network install scenario. I suggest you instead write the XML file to your plugin's state location which is intended for just this purpose:
String path = Activator.getDefault().getStateLocation().toString();
I should add that this gives you a fully qualified path to the directory created by Eclipse for any files your plugin wants to store. This directory is unique to your plugin.