I have several launch configurations in Eclipse each launching the same Java program but with different parameters.
Now is it possible to run all of these at once (with one mouse click) instead of selecting each of it separately and launching it?
EDIT: According to this answer since Eclipse Oxygen (4.7.0) you can use a run configuration of the type Launch Group for that.
Just install "C/C++ Development Tools" from the CDT (see eclipse.org/cdt/downloads.php ) - this single package is enough, no other CDT packages are needed. This won't disturb your Java environment ;-) Then you have "Launch Groups", for any kind of project, including Java projects. See the following screenshot:
You can run or debug the projects (also mixed mode), define delay times and so on. Have fun!
I found this post on the Eclipse trackers: Start multiple debug configurations at once
While it talks about multi-launching debug configurations, I think it is just as applicable to run configurations.
You may want to right click a run configuration in group launch and configure it.
Since Eclipse Oxygen (4.7.0) you can use a run configuration of the type Launch Group for that.
This short video shows how to use a Launch Group.
There are two more options listed in Launch an Eclipse Run Configuration from ANT.
You could group them in Ant and then call them using Ant4Eclipse. Or call multiple launch configs from a command script using eclipse remote control.
You can create a separate class that calls your program with different arguments, and run it instead.
public class YourClass {
public static void main(String arg){
System.out.println(arg);
}
}
public class YourClassTester {
public static void main(String[] args){
YourClass.main("SomeArg1");
YourClass.main("SomeArg2");
YourClass.main("SomeArg3");
}
}
You don't need any plugin:
Create all Run Configurations in eclipse
Select Organize Favorites...
Add you favorites, done
Related
I am using Hot Code Replace feature when Tomcat is running from eclipse and it works great.
But, how can I do this manually when Tomcat is running outside eclipse?
After some searching, I have found that I need to use an agent like HotswapAgent. But, they are using this agent with modified JDK called DCEVM. I don't want to use modified JDK. I want to achieve the same thing with OpenJDK.
I know that modification will be limited to method body only but, that's not a problem for me. How can I achieve the exact same thing eclipse is doing for Hot Code Replace for an externally running Tomcat without using IDE?
Edit : Eclipse example is just to clarify what I want to achieve. I do not want to use eclipse at all. I just want to do Hot Code Replace in an application running in Tomcat.
Yes, it's possible to perform Hot Code Replace in a running JVM. This involves several steps.
Prepare (compile) the new version of classes you want to replace. Let's say, you want to replace org.pkg.MyClass, and the new version of this class is located at /new/path/org/pkg/MyClass.class
Create a Java Agent that uses Instrumentation API to redefine the given class. Here is how the simplest agent may look like:
import java.lang.instrument.*;
import java.nio.file.*;
public class HotCodeReplace {
public static void agentmain(String args, Instrumentation instr) throws Exception {
Class oldClass = Class.forName("org.pkg.MyClass");
Path newFile = Paths.get("/new/path/org/pkg/MyClass.class");
byte[] newData = Files.readAllBytes(newFile);
instr.redefineClasses(new ClassDefinition(oldClass, newData));
}
}
Compile the above agent and pack it into .jar with the following MANIFEST.MF
Agent-Class: HotCodeReplace
Can-Redefine-Classes: true
The command to create HotCodeReplace.jar:
jar cvfm HotCodeReplace.jar MANIFEST.MF HotCodeReplace.class
Load the agent .jar into the target JVM. This can be done with Attach API or simply with jattach utility:
jattach <pid> load instrument false /path/to/HotCodeReplace.jar
More about Java agents ยป
I am devoloping an application with eclipse RCP. This application should alwaysshow a certain perspective when started. But the application saves it workbench state and when restarted it shows the same perspective it had when it was closed. I tried to add
public void initialize(IWorkbenchConfigurer configurer){
configurer.setSaveAndRestore(false);
}
to my ApplicationWorkbenchAdvisor class, but it did'nt work. I also thought of selection the right perspective, but I don't know where to add such a piece of code.
How can my application always show the same perspective on startup?
Too late for you but maybe usefull for other people.
As #Aiden says, we add -clearPersistedState to the program arguments in run configurations.
It worked for us in e4 with Eclipse Neon 4.6.
I found out that if you always want the same start perspective, you can set the default perspective during startup.
public class Application implements IApplication {
public Object start(IApplicationContext content){
PlatformUI.getWorkbench().getPerspectiveRegistry().setDefaultPerspective("youperspective here");
//other code...
}
//other code...
}
UPDATE:
This only works if you enable "Clear workspace" in your run configurations. My current solution is to delete the workbench file during program startup.
I have a parent pom.
When I am on the parent and write mvn clean install my dropwizard application builds fine.
However, in Intellij it fails because it cannot find my config.yml file.
The problem is that I need to include my module directory in Intellij, but not in Maven. Why is that?
Running mvn install this works
public static void main(String[] args) throws Exception {
new CivilizationApplication().run(new String[]{"server", "src/main/resources/config.yml"});
}
In Intellij I must change to the following
public static void main(String[] args) throws Exception {
new CivilizationApplication().run(new String[]{"server", "civilization-rest/src/main/resources/config.yml"});
}
How can I configure Intellij, so it will work without specifying the module directory?
You could try setting your working directory in your run configuration...
I would also look into your pom.xml configuration to see if you can change the working source sets to use this directory upon importing the maven project.
Set Working directory to $MODULE_DIR$. Maven always uses $MODULE_DIR$, but you probably do not have $MODULE_DIR$ by default for IntelliJ Application executions.
You can just tell Intellij to do exactly the same thing Maven does when you start it.
You can do so by clicking on the drop down menu next to the "Launch App" button. There you can define a new Run configuration that uses Maven by clicking on the + to the left and then choosing Maven.
Then you can just enter clean install exec:java where it says "Command line" and it should work exactly like it does when you execute it manually from the command line. Debugging should work like this as well without any problem.
The problem here is that you are refering to a resource file by using a relative path instead of using the classpath.
So, instead of
new CivilizationApplication().run(new String[]{"server", "src/main/resources/config.yml"});
You better have this
new CivilizationApplication().run("server", getClass().getResourceAsStream("config.yml"));
(obviously, make sure to change the signature of the #run() method as well)
Just a thought but maybe it's to do with the Resource not being copied.
I'm on OSX so the exact terms may differ if you're on Windows but for me... in Preferences, select "Build, Execution, Deployment", then "Compiler", and try adding ";?*.yml" to the Resource patterns.
I am just starting to use Nitrous.IO and I can't seem to find any information on the web on how to run Java programs you make in it. Any help on how to run a java app made in Nitrous would be a huge help.
You can check the version of Java by running java -version, which shows Java SE is installed. This does not include all of the components of JDK8, but you can still build Java apps on it. Take a look at the JDK8 diagram for an overview of the components included.
To build a simple hello world app, create a new file titled HellowWorldApp.java with the following contents:
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
Once saved, run the following command to build a class file:
javac HelloWorldApp.java
You should now have a file named HelloWorldApp.class. Run this application with the following command:
java HelloWorldApp
Currently you can utilize this on any box template on Nitrous, but there will be full Java support in the near future.
I recently created a new project using Maven and everything seems to work fine.
More details on: Maven Getting Started Guide http://maven.apache.org/guides/getting-started/
But when I installed the Play framework (https://www.playframework.com/) and run a project i.e:
activator "~run 8080"
and previewed at http://my_box_name.nitrousbox.com::8080/ The web app suddenly died, with a log message: "killed"
After a short research it seems that I do not have enough resources on my box for this type of development (have to buy more N2O :) ).
In conclusion it is okay to use Nitrous for Java Development, especially for prototyping things (Plus they are currently working to make it better). Good luck !
I am executing a junit test case
I got the following error,
A fatal error has been detected by the Java Runtime Environment:
Internal Error (classFileParser.cpp:3174), pid=2680, tid=2688
Error: ShouldNotReachHere()
JRE version: 6.0_18-b07
Java VM: Java HotSpot(TM) Client VM (16.0-b13 mixed mode windows-x86 )
Can any body please suggest the solution to resolve
I got the same problem, but with alot of googling I found the answer! See this page
Quote from the link:
# An unexpected error has been detected by Java Runtime Environment:
#
# Internal Error (classFileParser.cpp:2924), pid=5364, tid=6644
# Error: ShouldNotReachHere
That's because we are using Android's JUnit stub implementation. Go to Run -> Run As -> Run configurations again and in the recently created JUnit configuration Classpath's Bootstrap Entries remove Android Library
Then Add Library, using Advanced... button, and add JRE System Library and JUnit 3
Apply and Run
Try this, it worked for me.
You'll need to take this up with Sun -- looks like a JVM bug to me. If it's reproducible, you should be able to run java in such a way as to generate more details (e.g. -verbose, etc). If you can reduce it to a minimal case that triggers the bug (source code always helps!), that also goes a very long way.
http://java.sun.com/developer/technicalArticles/bugreport_howto/index.html
http://bugreport.sun.com/bugreport/crash.jsp
In the meantime, you might want to try it with a different JVM implementation (maybe even an older patch level of the Sun JRE).
Go to Run As -> Run Configurations... and select the configuration you are using.
Select the Class Path tab and select BootStrap Entries.
Click on Advance, then Add Library and select JRE System Library.
Bring it up and make it the first entry in the BootstrapEntries List.
Apply and Run...
Another possible explanation: hardware failure. Ruled out if you can reproduce the error on different machines.
I resolved this by
Quit eclipse
Delete the bin and gen directories in your project
Start eclipse
Rebuild your project
I just recently found solution for this issue that was posted by devdanke:
"As of 11-July-2010 and Android 2.1, the work around I use is to segregate tests into different classes. Any test(s) that don't call any Android APIs go into their own classes. For each of these classes, I remove the reference to Android in their Run Configurations, Classpath tab."
The problem with having it configured class by class is then is not possible to run all tests in project. Better approach is creating 2 test projects with different sets of libraries.
Standard Android JUnit Test project can be created following link, and sample test class looks like:
import android.test.AndroidTestCase;
public class ConverterTest extends AndroidTestCase {
public void testConvert() {
assertEquals("one", "one");
}
}
Then JUnit Test project can be converted from Android JUnit Test project by removing Android Library from project build path, and adding JRE System Library, and JUnit 3 library, and sample test class looks like:
import junit.framework.TestCase;
public class ConverterTest extends TestCase{
public void testConvert() {
assertEquals("one", "one");
}
}
I have had a similar problem, I found it was because I had generated a new activity with a main[] stub entry. Once I deleted the main[] code from the new activity templatye the error went away.
YMMV
This could be a JVM bug; see #Zac's answer. But it could also be that your junit test case is causing a corrupted bytecode file to be loaded. Try rebuilding all your .class files, and if that does not fix the problem try refetching any external libraries that your code depends on.
Do you run on a supported platform (Windows, one of a few Linux versions?) If not, that is the first to try.
If you ARE on a supported platform, then downgrade to _17 and see if THAT helps.
Then make a bug report to Sun and hope they will fix it someday (unless you want to give them money for fixing it faster).
Go to Run As -> Run Configurations->classpath->BootStrap Entries
Click on Advance, then Add Library and select JRE System Library as a first entry.
Apply and Run...
I am not sure whether you were able to reach the solution for your problem or not but your question just popped up while I was searching for the solution for the same problem I am facing. And I got one solution from the stack itself, so just thought to share a link with you if that aids you by any means. The link is as below:
Can't run JUnit 4 test case in Eclipse Android project
Another possible reason (for future references):
I had accidentally copied in a main method in my code, causing Eclipse to recognize the project as a java application, thus launching it with that configuration.
To solve it I went into Run > Run Configurations... and then changed from my presumed main in java application to the main activity of my android application simply by choosing it in the left column.