how to build a runnable jar file in intelliji 14.1.4 - java

i'm having issues in creating a runnable jar file using the intelliji EDK, i have tried this before in the Eclipse EDK and it was a succes, yet i don't seem to find any luck with this one.

Follow below steps to create a .jar using IntelliJ IDEA 14.1.4:
1.File > Save All.
2.Run driver or class with main method.
3.File > Project Structure.Select Tab "Artifacts".
4.Click green plus button near top of window.
5.Select JAR from Add drop down menu.
6.Select "From modules with dependencies"Select main class.
7.The radio button should be selecting "extract to the target JAR."
8.Press OK.Check the box "Build on make"Press apply and OK.
9.From the main menu, select the build dropdown.
10.Select the option build artifacts.

Related

Java Netbeans 8.2 Debugging: Error: Could not find or load main class some.main.Class

I am trying to debug a java file in netbeans 8.2 and I am getting this error. I have seen posts on netbeans 8.0 that show where to set the main class but it has moved in 8.2. Can someone point me to what I need to change to allow debugging in netbeans 8.2
Under the categories menu there should be a run option to make this setting but I do not see a run option.
There is run listed under the categories menu, however, there is no setting for main class.
First off...does the file you're trying to run contain a main() method? If not then there must be a class that does. You can select which Class will be considered the Startup Class by doing this:
With you mouse pointer, select the Project Name within the Projects
pane typically located on the left side of the NetBeans IDE;
Right-Click on the Project Name and from the popup menu select
Properties;
From the displayed Project Properties windows select Run from
the Categories pane;
On the right side of the Project Properties window you will notice a
label stating: Main Class. The Class which is considered the
Startup Class is displayed within the Text Field. Select the
Browse button located at the far right and then select your desired startup class from the Main Classes popup dialog window;
After selecting your desired startup Main Class select the Select
Main Class button to close the popup dialog then select the OK
button located at the bottom of the Project Properties window;
Done. Run your application.

Eclipse right click new project preferences

Well, honestly, it is a simple question I can't find on eclipse nor google.
I am a lazy dev and want to add the Maven Projectoption to my [right click]->New->(Maven Project). But can't find an option in the preferences. Every Javaproject I create is a maven project (DM FTW, YEA!)
In PHPStorm I can simply add/edit an entry in a config section and I am done. It gets added to any "New" context.
Can I do something like that in eclipse? Add completely new "New..." entries to create a templated new file type and (the original topic) can I add another menu entry without writing a plugin?
Thank you in advance!
open eclipse, then go to Window menu, select Customize perspective...
a windows appears. it has for tabs.
Tool bar visiblity
Menu visiblity
Command Groups Availablity
Shortcuts
select Menu visiblity tab, it will shows all menus with tree view.
then expand tree view of File then do same for the New which is sub tree of File.
now select All of those project types that you want, then click Ok.
The concept is:
new means creating a bare project begining from zero,
adding means import some project that you/other have/has started...
in eclipse import is the menu you need to click to, then maven, then select the proj option the best fits you...

Netbeans - Error: Could not find or load main class

So I'm making a java application in Neatbeans 7.4, been working at it for a while, everything was fine, running the project worked fine, but now when I hit run project, I get the error
Error: Could not find or load main class phleveledit.MainWindow
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
I can't think of what I did right before this started happening, so I don't know what I should change.. The code doesn't appear to have any errors. Here's a screenshot of the IDE+project folder
Image (http://puu.sh/5ldYB) :
Any ideas?
Edit: Unfortunately I happened to fix this problem by removing some code, which probably had some errors Netbeans couldn't detect, but I don't know what was exactly wrong so can't vote on a correct answer.
Right click on your Project in the project explorer
Click on properties
Click on Run
Make sure your Main Class is the one you want to be the entry point. (Make sure to use the fully qualified name i.e. mypackage.MyClass)
Click OK.
Clean an build your project
Run Project :)
If you just want to run the file, right click on the class from the package explorer, and click Run File, or (Alt + R, F), or (Shift + F6)
Just close the Netbeans. Go to C:\Users\YOUR_PC_NAME\AppData\Local\Netbeans and delete the Cache folder. The open the Netbeans again and run the project.
It works like magic for me.
(AppData folder might be hidden probably, if so, you need to make it appear in Folder Options).
You can :
RightClick on project node and go to Set configuration
Select the main class for your application.
Then clean and build.
Even if the above steps don't work for you then then delete the Netbeans cache by deleting the (index) folder
User\.netbeans\SOME_NUMBER_reflecting_your_version\var\cache\index\
Sometimes due to out of memory space error, NetBeans does not load or find main class.
If you have tried setting the properties and still it is not working then try
Select the project from the project explorer
Click on Run in the Menu Bar
Click on Compile
It worked for me.
This condition happens to me every 6-months or so. I think it happens when closing NetBeans under very low memory conditions. I discovered that it could be easily corrected by (1) Rename your project, including its folder name using right-click on project explorer's project name---I put a simple suffix on the original name ("_damaged"). (2) Try BUILD. If that is successful, which it is for me, give three cheers. (3) Repeat step (1) to restore the original project name. BUILD and RUN should start without trouble.
I guess that the 'rename the project and folder' process causes a special rediscovery of the applications main location.
Try to rename the package name and the class/jframe names... The clean and build the application.
Right Click on the package name
Go to Refactor
Select Rename
Give it a meaningful name, preferably all in small letters
Click on Refactor
Do the same for the class/jframe names.
Last Select Run from Menu
7.Select Clean and build main project
That should do it!!! All best
I had the same issue once. The problem was not in the code. The cause was... renaming the project folder to some other non supporting name. My project name was "MobStick" and I renamed it to "MobStick - May 26, 2014 04:00PM". Renaming it back to normal solved my problem.
I have run into this error a couple of times as well and for me the above solutions did not work. What does seem to work is going to the Project Properties, and under Compiling toggling Compile on Save.
Using NetBeans 8.1, I got the dread
Error: Could not find or load main class
from carelessly leaving an empty line in the Project Properties > Run > VM Options field. Until you click in the field, you may not see the caret flashing out of place. Remove the empty line to restore equanimity.
I just ran into this problem. I was running my source from the command line and kept getting the same error. It turns out that I needed to remove the package name from my source code and then the command line compiler was happy.
The solutions above didn't work for me so maybe this will work for someone else with a similar problem.
I had the same problem, I had the package and class named the same. I renamed the class, then clean and build. Then I set the main class in the "run" under the properties of the project. I works now.
I found the following steps useful:
Right-click on the project in the left toolbar.
Hover over the 'Set Configuration' item.
Click on 'Customize...'
Click on 'Browse...' by the 'Main Class:' item.
Select the correct class.
Click 'Select Main Class'.
Click 'OK'.
My problem was that, apparently, my package name was being listed twice. Selecting the class using the dialog changed 'aclass.MainClass' to just 'MainClass'.
Hope this helps,
-HewwoCraziness
Edit: This is expanding on Mary Martinez's answer.
You can solve it in these steps
Right-click on the project in the left toolbar.
Click on properties.
Click on Run
Click the browse button on the right side.(select your main class)
Click ok
Possible Fixes:
Fix 1
Go to project properties (right click on the folder of your project in netbeans)
On left tab where it shows the categories, click on the "Run" selection
Then click on Browse to find the Main class you use on your project
Fix 2
Go to C:\Users\name\AppData\Local\Netbeans
delete the Cache folder.
Rebuild and Run
Fix 3
Download most recent version of Netbeans
Fix 4
Download most recent version of JDK and configure Netbeans to use that
I had the same problem for 3,4 days. On my PC my Jar file snapshot would give me this error while on my laptop it would work fine, I tried all the tricks shown above and on other forums like deleting cache, selecting main project file, etc, but somehow I was sure the reason it cannot find the main class when I would execute the JAR file was may be due to classpath issue in maven configuration, and I was right and I fixed it using following steps:
Right-click on the project, and go to the properties
Inside the properties go to Actions
On the right side in Actions select "Run Project" and you will see properties below
Inside "Set Properties" make sure exec.args=classpath %classpath "package_name"
In my case, the package name was accompanied by the main class. So my main class was Login while the package name was com.mycompany.islamic_center_app1, When I checked the entry was
com.mycompany.islamic_center_app1.Login
All I did was remove ".Login" from com.mycompany.islamic_center_app1 and it was fixed, no more errors.
close netbeans.
open netbeans again.
choose new project>>java application.
click next.
deselect create main class.
now make the application
clean build run
For more reference watch this video
try this it work out for me perfectly
go to project and right click on your java file at the right corner,
go to properties,
go to run,
go to browse, and then
select Main class.
now you can run your program again.
I had the same problem and I moved the project to a location where the path had no none-english letter and that fixed the problem
if you are on window os, then try to start NetBeans via administrative mode. right click on NetBeans icon and "Run as Administrative".
If none of the above works (Setting Main class, Clean and Build, deleting the cache) and you have a Maven project, try:
mvn clean install
on the command line.
Had the same problem here. Usually Clean and Build solves much of the problem. It happened to be caused by a wrongly installed plugin.
I faced the similar issue with Netbeans 10 and JDK 1.8.
I was not able to choose the right class to launch the project
When I compile or run the project, it shows me the Class name as "initializing view, please wait ...", I could not select the class name.
The issue was resolved with the NetBeans11.3, I am able to choose the correct Class file without any other changes, and the project is launched without any issues.
I had the same issue but none of this thread's solutions worked for me. Finally, it was OneDrive that caused the issue (for once more). So, I simply moved the NetBeansProjects folder from Documents which is synced with OneDrive, to C:\Users\yourName\AppData\Local\NetBeans (selected this path as there is already a NetBeans folder) and that was it, case closed.
If you also have NetBeansProjects to a OneDrive syncing folder it is worth trying this solution, just be sure that the path you will select is not synced with OneDrive. Also, remember to close Netbeans before making the folder change and after you move the folder to the new path you need just to open Netbeans again, go to file menu/open project and select your project from the new path.

Can't run SWT app in Eclipse

I was following the tutorial that came in the Eclipse editor (click Help -> Welcome -> Tutorials). I worked through all the steps which were:
This cheat sheet shows you how to create a "Hello World" application
that uses the Standard Widget Toolkit (SWT). The application will
simply display an empty window to the user. If you need help at any
step, click the (?) to the right. Let's get started!
If you're not already in the Java perspective, in the main menu select
Window > Open Perspective > Java or click on the "Click to Perform"
link below.
Open the Import wizard from the main menu via File > Import..., and
select Plug-in Development > Plug-ins and Fragments. Click Next. On
the Import Plug-ins and Fragments page, select Import from: The
active target platform. Plug-ins and Fragments to import: Select from
all plug-ins and fragments found at specified location. Import As:
Projects with source folders. Click Next. On the Selection page, Add
org.eclipse.swt.{platform}.{os}.{arch} (for example:
org.eclipse.swt.win32.win32.x86 for win32) to Plug-ins and Fragments
to Import: list. Click Finish. This will create the
org.eclipse.swt.{platform}.{os}.{arch} project which we will need to
compile and run the application.
Now we need a project to store our own source code. In the main
toolbar, click on the New Java Project button, or click on the link
below. Enter HelloWorldSWT for the project name, then click Finish.
Since our project requires SWT, we need to specify this in the project
properties. Right-click on the project and select Properties. In the
Java Build Path page open the Projects tab, add the
org.eclipse.swt.{platform}.{os}.{arch} project, then click OK.
The next step is to create a new class. In the main toolbar, click on
the New Java Class button (or the link below). If not already
specified, select HelloWorldSWT/src as the source folder. Enter
HelloWorldSWT for the class name and select the checkbox to create the
main() method, then click Finish. The Java editor will automatically
open showing your new class.
In the Java editor, enter the following Java code in the main()
method: Display display = new Display(); Shell shell = new
Shell(display); shell.setText("Hello world!"); shell.open(); while
(!shell.isDisposed()) { if (!display.readAndDispatch())
display.sleep(); } display.dispose(); You will get compile errors.
Right click in the Java editor and select Source > Organize Imports,
then save your changes.
To run your application, right-click on your class in the Package
Explorer and select Run As > Java Application. A new empty window
should appear with the title "Hello world!". Congratulations! You have
successfully created a Hello World SWT application!
And here's a screenshot:
But when I tried to run the program, instead of displaying a blank screen as expected, it dumped this in the terminal:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons:
no swt-cocoa-4233 in java.library.path
no swt-cocoa in java.library.path
Can't load library: /Users/devenkelling/.swt/lib/macosx/x86_64/libswt-cocoa-4233.jnilib
Can't load library: /Users/devenkelling/.swt/lib/macosx/x86_64/libswt-cocoa.jnilib
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:331)
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:240)
at org.eclipse.swt.internal.C.<clinit>(C.java:21)
at org.eclipse.swt.widgets.Display.<clinit>(Display.java:101)
at HelloWorldSWT.main(HelloWorldSWT.java:11
I'm using an x64 system with the 64-bit Eclipse installed and both 32-bit and 64-bit versions of Java (I think). Please help. Thanks.
Source: Eclipse Forums
This worked for me:
Right-click on your your project folder HelloWorldSWT;
Go to Properties -> Left Sidebar Java Build Path -> Tab Projects;
Expand the org.eclipse.swt.cocoa.macosx.x86_64 folder by clicking on the arrow left to it;
Select Native library location and click Edit;
Click the Workspace button and select org.eclipse.swt.cocoa.macosx.x86_64;
Click OK a couple of times;
And you're done! Hope this helped.

How to import existing project into Workplace in Eclipse?

I am trying to follow Eclipse instructions to create a Hello World SWT application. I have the following instruction:
Import the SWT project from the main
menu via File > Import..., and select
Existing Projects into Workspace.
Specify the archive file you
downloaded and click Finish. This will
create the org.eclipse.swt project
which we will need to compile and run
the application.
I have troubles with that. In the "File" menu I see "Import...". When I click the "Import...", I do not see "Existing Project into Workspace". Instead of that I see "Select an import source:" after which I see a text field. After that I see a field with the following folders: General, CVS, Run/Debug, Tasks, Team, XML.
Can anybody help me with that, pleas?
You need to expand General.
If you expand the 'General' node (folder) you will see 'Existing projects into workspace' as an option. Select that and click on Next.
Eclipse has the wonderful search functionality on most of its important screens. Even if you don't know where exactly it is, you can type it and it appears. In this case type "Existing" into the text field above the list and you'll see what you are looking for.

Categories