first i created a scala class inside a scala project in eclipse ide as below and ran it, it was successful.
object Test extends App{
println("hi");
}
once i rename the object , i can not find any option to run the program. [The file name is not changed and build automatically was enabled]
object Test1 extends App{
println("hi");
}
any advice ?
Try to change launch configs for your application. Clean target folder before re-build. For config you can refer to:
Select Run > Run Configurations... or Run > Debug Configurations... from the workbench menu bar. This opens a dialog
that lets you create, modify, and delete launch configurations of
different types.
Related
I have a java main program in my gradle project which I can run via command line using the gradle application plugin run task with --args param new since gradle 4.9 as follows:
gradle run --args="-ahttp://foo.com/bar -dmydeviceid"
I would like to create a Run Configuration for the same in IntelliJ IDEA CE 2018.1.
I specify Task field in Run/Debug Configuration dilog as run.
I specify Arguments field as --args="-ahttp://foo.com/bar -dmydeviceid"
When I run this run config I get the error:
11:58:31 AM: Executing task 'run --args="-ahttp://foo.com/bar -dmydeviceid"'...
Unknown command-line option '--args'.
How can I make this work via run config?
The solution is to create a new Run Config as follows for the main program:
Open Run/Debug Configurations dialog vie Edit Configuration choice in pulldown left of Run button
Expand Defaults menu and select Application
Click + to create an Application run config
Enter your Main class
Enter program arguments. For my example above it was: -ahttp://foo.com/bar -dmydeviceid
Enter module in "Use classpath module". It is likely the one with suffix "_main"
Click OK
Now click run or debug button
I have a TestNG class file.
Whenever I try to execute it, I get the "Run As" options to select between Java Application and TestNG Test.
How do I default it to take always TestNG for this class file, whenever I execute it? Is there any association for class files to the way it has to run?
I've tried Window->Preferences->Run/Debug and in the Launch Operation -Setting it to option --> Always launch the previously launched application.
But, that doesn't solve my problem as that executes the previous launched application always even if I open another class file with a main to it.
I am using IntelliJ IDEA 2017.3. I have a project called "test", which has two classes under the src folder:
Main, has main method to print out "Hello World"
CompileErrorClass, has one method with compile errors
Those two class have no dependencies. I was trying to run the main() in the Main class, and set the before launch to "build, no error check"
I got an error message
"Error: Could not find or load main class Main".
When I fixed the compile error in CompileErrorClass, the main() worked as expected. Or if I ran the same project in Eclipse, it worked fine even with compile error.
How can I setup the run configurations in IntelliJ to run a single class ignoring the compile errors in other class without dependencies?
To be able to run code with errors you need to make a change in the settings. Go to Build, Execution, Deployment | Compiler | Java Compiler and set the Use compiler: combobox to Eclipse and enable the proceed on errors checkbox. This allows to compile classes even when they have errors.
To start a Run Configuration when the project has errors, you will need Build, no error check in the Before Launch section, instead of Build.
You can put your CompileErrorClass in a folder, then go to "Project Settings/Module" and mark the folder as "Excluded". The folder will be shown on red.
Shorcut: you can "right click" the folder an select "Mark Directory as Excluded".
In the image you can see the "bean" directory in red.
If you want to run the 'main()' method in the Main class and see the output without fixing the errors in the CompileErrorClass:
Select the 'Main' class in the project view, go-to Run --> Edit Configurations --> Before Launch and in Before Launch click + and select Build, no error check or click '-' take-out(delete) any setting in there --> Click Ok. If you take-out(using '-') any setting, then 'Before Launch' should not have any setting, its setting should be empty, null.
After the above, right-click on the Main class, and run it. You would see the output. You would see the output even if Use Compiler, which is at Settings --> Build, Execution, Deployment -->Compiler --> Java Compile --> Use Compiler, has javac selected as the compiler.
The steps are as follows:
Set Do not build before run (only need to set it once)
Menu → Run → Edit Configurations...
☑︎ Your run configuration
Run / Modify options → Java / ☑︎ Do not build before run
Recompile only selected files (remember to do this step before run)
Select packages or files that needs to be compiled.
Menu → Build → Recompile selected files (⇧ ⌘ F9)
Run or debug your run configuration.
I am working with Eclipse and I've been doing it since several months ago without any problem. Now I've created a new class in a certain package, but Eclipse does not compile it.
So I tried to create a new simple class:
public class Test {
public static void main(String[] args) {
System.out.println("Hello");
}
}
But I get always this error:
Errore: impossibile trovare o caricare la classe principale Test
(Error: impossible to find or load main class Test)
I compiled it with cmd: in that case, Eclipse can run the java file, but it can't create the .class file with new edits; it just launches the last version of the compiled file.
I tried to uninstall and reinstall Eclipse, but still got this problem.
If you create a java class with public static void main(String[] args), Eclipse will run that main method for you by right clicking on the file itself, or on the file in the project explorer, then choosing:
"Run As" -> "Java Application."
Once you do this, Eclipse stores information about your class, so you can easily run the class again from the Run As menu (Green Play Button on the toolbar) or from the Run Configurations dialog.
If you subsequently MOVE the java class (manually, or however), then again choose
"Run As" -> "Java Application,"
from the new location, Eclipse will run the original stored configuration, attempt to invoke this class from its original location, which causes this error.
For me, the fix was to go to the run configurations, (Green Play Button -> Run Configurations) and remove all references to the class. The next time you run
"Run As" -> "Java Application"
Eclipse will write a new configuration for the moved class, and the error will go away.
Original Source of this answer
have you tried to change JDK? be sure to download the last version
I solved by deleting everything I had on Eclipse, but when I opened a new Eclipse it gave me the error. So I created new projects, by importing one by one the single java files, then it worked.
I'm using Eclipse; when I run my code in debug I get a class not found exception but running it without the debug it works fine.
I see it doesn't find the classes I wrote.
How can I fix this?
Double-check that the Run Configuration in Eclipse has the same classpath set for both (running it normally vs debug).
Eclipse has a lot of settings but I would try checking the following:
Run > Debug Configurations > Java Application > PROJECT_NAME > Classpath
Also, you can check your source under the same location to make sure all of your JAR files have been properly added.
I assume we're looking at a normal Java Application. Eclipse creates Run Configurations for normal execution and Debug Configurations for debug runs. And there's usually no significant difference between a Run and a Debug configuration for the same class.
The easiest way would be to start clean: Navigate to 'Run Configurations...' and delete all 'Java Application' configurations. Then do the same for 'Debug Configurations'. After this is done, start your application once in normal and once in debug mode.
Alternative: switch to a new workspace (File -> Switch workspace), import the project(s) (File -> Import... , make sure to copy content) and run/debug your application.
Check your run/launch configurations. You probably have a different configuration for debug vs run. Chances are that the debug one isn't pointing to the main class of your program.
Just check the debug... option (pull down the debug menu don't click the button, then click debug...) and the first page should have a field for "Main class". Use the same main class as in your run... option.