Use /src/resources as source directory for a new package - java

I would like to create a new package in Inteliji IDEA (Community Edition) where the source directory is /src/main/resources. I am trying to create a simple forge mod, and need to create several packages in resources for handling textures and other assets. My file structure looks like this:
Main
>Java
>com.mycompany.project
>Package1
>Package2
>Main.java
Resources
>mcmod.info
>pack.mcmeta
Is there any way to create a package in /src/main/resources? I have seen examples of this being done in Eclipse, but I would prefer to not have to use two IDEs.

Please refer to the documentation.
I believe you can do it by right clicking on Resources folder, then New -> Directory and then specify the package com.mycompany.project. Intellij will create the hierarchical package structure.

Related

Export custom library to importable jar file java

I have created a custom package in Java. The directory structure is like this:-
wolpha
/Stream>Stream.java
/Word/Stream.java
/Pattern/Stream.java
/Stream/Stream.java
So I just made a non runnable jar file and tried to import the package but it gave a error that the package wolpha does not exist. Tried with a main class with imports included but gave the same error.
How can I add all these classes into a single .jar file such that all classes can be imported into any file. I expect some step-by-step instructions with some down-to-earth language.
If you are using eclipse, go to File > Export and follow the instructions as per the screenshots given below:

GWT How to Modify default project sample code?

When we create a new GWT project using the Eclipse plugin, it gives an option to generate sample source code for the project as shown below:
Selecting the above option, generates sample code structure that looks something like this:
MyTestProject
src/
com/
mytestproject/
MyTestProject.gwt.xml
client/
GreetingService.java
GreetingServiceAsync.java
MyTestProject.java
server/
GreetingServiceImpl.java war/
MyTestProject.css
MyTestProject.html
WEB-INF/
web.xml
classes/
lib/
...GWT JARs...
I wanted to know if there is a way to modify/customize this default code to automatically generate a few more classes to jump start my projects. Any suggestions to get me started in the right direction will be appreciated. For example how do I find the source from where this code is getting generated or more popular approach to create such templates for kick-starting a new project.
You can create your own sample/template project with as many classes as you need, add it to a git/mercurial repository, and import from this repository every time you start a new project.

How to generate package structure from standalone *.java source files?

I've been searching for answer for my problem but I can't find some relevant information, so I'm asking. I've directory which contains thousands of Java classes with source code (*.java files). Each of those files contains information to what package the file belongs, its classnames + code itself of course. I need to find some function of the Eclipse IDE (or maybe of another IDE) which is able to reconstruct packages under the 'src' directory based on the information in the class files and bring to me a good Java project structure so the restored packages and its classes can be easily imported into a new Java project then. Creating the structure of packages manually would take me (maybe) lot of days...
For clarification:
I have:
directory which contains: 1.java, 2.java, 3. java, n.java...
I need:
directory which will contain:
[src] -> [package_1] -> [1.java, 2.java, etc...]
...
[src] -> [package_m] -> [3.java, n.java]
I think this must be possible somehow as the each class file contains information to which package it belongs actually.
Just if you find no better solution: At least you can import all sources into a project in Eclipse and have Eclipse move each file to the right package by means of using the quick fix for each problem. You still need to press 3 keys per wrong package declaration, but it saves you from fiddling with files and folders.

Java Package Vs Folder-Structure? what is the difference

I would like to know What are the difference between folder-structure and package used in Eclipse IDE for Java EE development.
When do we use which one and why?.
Whats should be the practice
create a folder structure like src/com/utils and then create a class inside it
create a package like src.com.util and then create a class inside it
which option would be better and easy to deploy if i have to write a ant script later for deployment ?
if i go for the folder-structure will the deployment is as easy as copying files from development to deployment target ?
If you configured stuffs correctly. Adding a folder inside src, is same as adding a package from File > New Package.
So, it's up to you, whatever feels comfortable to you -- add a folder or create a package. Also, when you put stuffs under src the package name starts from subfolder. So, src/com/naishe/test will be package com.naishe.test.
Basically there is no difference, both are the same.
In both the cases, the folder structure will be src/com/utils.
and in both the cases, you will need to mention
package com.utils;
as first line in the class
Since it doesn't have any difference practically, it won't make any difference to ant script.
"Packaging helps us to avoid class name collision when we use the same class name as that of others. For example, if we have a class name called "Vector", its name would crash with the Vector class from JDK. However, this never happens because JDK use java.util as a package name for the Vector class (java.util.Vector). So our Vector class can be named as "Vector" or we can put it into another package like com.mycompany.Vector without fighting with anyone. The benefits of using package reflect the ease of maintenance, organization, and increase collaboration among developers. Understanding the concept of package will also help us manage and use files stored in jar files in more efficient ways."
check out http://www.jarticles.com/package/package_eng.html for more information on packages
create a package like 'src.com.util'
That sounds like a mistake. The package name should be 'com.util', and 'src' is the name of the source folder.
Other than that, I fail to see what the difference is between your two choices. The result is the same, right? Just different steps in the GUI to arrive at it. The wizard to create a new package in Eclipse is just a wrapper around creating the appropriate folder hierarchy within a source folder.
You don't need to create empty packages at all, you can directly create classes (the package will be created automatically if it does not already exist).
A package is automatically "source folder" where folder is just a normal folder.
When you compile an Eclipse project, all files in source folders are compiled but not in regular folders (unless those regular folders a)
folder structure or to be specific source folder in eclipse is meant just for eclipse but package is universal irrespective of any editor..

Create a jar file from the java code

i want to create a jar file from java program i looked at some examples Java code to create a JAR file but it didnt impressed me as this will not create the proper package structure my original command was
jar -cfv formBuilder.jar .\com\accenture\* .\com\wysiwyg\util\XmlUtil.class .\com\wysiwyg\exception\ApplicationException.class .\com\wysiwyg\constants\*.class .\com\wysiwyg\util\FormBuilderUtill.class .\com\wysiwyg\util\SaveFormOnLocalUtil.class .\com\wysiwyg\logger\LogInfo.class .\com\wysiwyg\factory\Validation.class
now i want to do the same using java code but without ant, and proper package structures should be created, is this feasible?
Use java.util.jar package for this work.

Categories

Resources