I am using Install4J 6.1.5 and I am trying to modify the classpath using a manually constructed vmoptions file and the slightly documented -classpath/a vmoptions file instruction.
It appears that the -classpath/a and -classpath/p options do not support paths with environment variables in them, at least in linux launchers. When I include:
-classpath/a ${HOME}/.ssheena-server/resources
To a vmoptions file, the ${HOME} appears in its' unaltered form in the launchers' -classpath parameter when I look at the java process using ps -ef:
-classpath /opt/bids/ssheena-server/.install4j/i4jruntime.jar:${HOME}/.ssheena-server/resources
Is there a way to use -classpath/a that will support using environment variables?
As of install4j 6.1.5, environment variable substitution in classpath modifications in .vmoptions files is not supported.
You could modify the .vmoptions file with an action in the installer. For example, you could use the installer variable syntax
${installer:sys.userHome}
in .vmoptions file and use a "Replace installer variables in text files" action to replace it at runtime.
Related
I have a setenv.sh file which contains environment variables of Spring MVC for Tomcat server. I can paste the file in Tomcat bin folder and run the application from terminal. But when I want to run it from Eclipse I should specify every variable separately. Is there a way to specify the path to the setenv.sh file from Eclipse so that Eclipse takes all the variables required from that file instead of specifying each and every variable separately?
Inheriting a project whose build.xml produces a .ear final product, I now need to pass a "-P" command line option to the jar tool, as explained in 7u80 Update Release Notes:
Starting with JDK 7u79 release, the jar tool no longer allows the
leading slash "/" and ".." (dot-dot) path component in zip entry file
name when creating new and/or extracting from zip and jar file. If
needed, the new command line option "-P" should be used explicitly to
preserve the dot-dot and/or absolute path component.
Is there a way to do that?
If I run a jar as follows
java -jar Name.jar arg1 arg2 arg3
it is understandable that when exporting (creating the .jar) I would have had to specify an Eclipse run configuration in order to identify the main method because there may be as many main methods as there are classes.
If I run a main program from within Eclipse, it silently creates a new run configuration which adds more clutter to the run configuration choices available when I want to export. If I do this for many classes, the chances are I have many essentially identical run configurations, with the only difference being the main method specified.
If I run a jar as follows
java -cp Name.jar package.MyObject arg1 arg2
java -cp Name.jar package.MyOtherObject arg1
then the Eclipse run configuration which identifies the main method is probably ignored. The entry point is identified on the command line. In this case, the fact that Eclipse requires a run configuration during the export process, seems to create a chore, but there seems to be no way to avoid this.
I prefer to run my .jar via the -cp option because it gives me access to many entry points. This way I don't have to re-export when I want to access a different entry point. The decision as to which entry point to use is postponed until the time I want to run. I don't have to decide when exporting. I preserve flexibility.
I know an alternative way is to just have an arg1 that specifies the task, so I can rely on just one run configuration that identifies the main method that has a big switch statement and then always invoke Java with the -jar option.
If I use -jar there is the clutter of many run configurations. If I use -cp there seems to be an nuisance step in the export process that involves the clutter of many run configurations. Is there a way to use Eclipse that avoids both of these problems?
Open the project and select File and Export and Java and JAR file. Do not select Runnable JAR file.
By default, every file in the project folder is check-boxed as a resource meant to be exported and you may want to un-check some or all of them. Unfortunately Eclipse does not remember this so you may have to un-check resources every time you are exporting.
Check-box the src directory which unfortunately makes it appear you want to export source but actually you need to check-box it in order to export the corresponding .class files.
Check-box Export generated class files and resources.
Browse to the destination JAR file that you want to export or overwrite.
Click finish.
Eclipse does not consider third-party JAR files to be resources in the above step 2 so you need to find a way to provide them to the -classpath or -cp when you invoke Java. The reason we need to do this is because when Eclipse exports a "JAR file" it doesn't seem to follow the build paths to your third-party JAR files. This is a capability that Eclipse has when it exports a "Runnable JAR file" but that's not what we are doing here. You can manually create a directory of your third-party JAR files and let Java expand a wildcard in -classpath.
Example Java invocation in linux:
java -cp ~/directory/destination.jar:/home/username/directory/thirdparty/"*" com.domain.package.MyObject arg1 arg2 arg3
Note that on linux we can allow bash to expand the ~ for your own JAR file, "destination.jar". For the third-party JAR files the long form /home/username is used because tilde expansion might not work in the middle of the string, just after the colon.
If we want to use the Java * wildcard -- not the same thing as the bash command line wildcard -- for the third-party JAR files, the * character must be quoted (made literal) in order for the wildcard to be passed to Java.
Exporting this way eliminates the need to select a run configuration and addresses the concern that prompted the question.
Aside: If your own JAR is exported to the same directory as the third-party JARs then classpath is simpler:
java -cp ~/singleDirectory/"*" com.domain.package.MyObject arg1 arg2 arg3
I would like to specify a specific Eclipse VM argument to all of the JUnit tests I run from Eclipse i.e.
-Dlog4j.configuration=log4j-dev.properties
This is because I want a specific log4j configuration file to be picked up by all my JUnit tests instead of the default log4j.properties file.
As of now I have to specify the above VM argument (in Run Configurations -> Arguments -> VM arguments) for each of my JUnit tests making it cumbersome because I have many tests.
You do not need to give the JVM a different property name. The logging code searches for the log4j.properties file using the classpath. So all you need to do is ensure that your test log4j.properties file is in a location that it will find before the release file.
I use Maven, which lays out files in directories to make that easy. My release log4j.properties goes in the directory src/main/resources. My test version goes in src/test/resources. The Eclipse build path (classpath) is set up to search src/test/resources before src/main/resources, so your unit tests use the test file. The JAR (or WAR) build instructions use the files from src/main/resources.
Eclipse gives you the ability to define default VM arguments that are applied to any launch which uses that VM. You could use that in your situation by defining a JRE configuration with the VM argument you want for log4j and then setting up all JUnit launches to use that JRE definition.
In Preferences, Java > Installed JREs and use the Add... button to define a JRE. In the JRE Definition dialog there is a field for Default VM arguments. Give this JRE definition a useful name such as "JDK 7 for JUnit" so that you can easily identify it.
Then in your JUnit launch(es), on the JRE tab, select the JRE definition you created.
In the run configuration of eclipse, you are provided with a set of default variables that you can use in the VM arguments, like container_path and env_var.
What I want to access is a classpath variable, M2_REPO, but can't see a way of doing this. I need to specify a javaagent in the VM arguments, which requires a path to a jar file. This jar file lives in the maven repository, but I can't find a way of specifying the path to the maven repository using the already configured M2_REPO Classpath variable (configured in windows->preferences->java->Build Path->Classpath variable). What I would like to do is use this as my VM arguments but can't because classpath_var isn't a real variable.
-javaagent:${classpath_var:M2_REPO}/org/apache/openjpa/openjpa/2.1.0/openjpa-2.1.0.jar
Is there any other way of accessing the value of M2_REPO in VM arguments?
This isn't exactly what you asked for, but it worked for us as a way of sharing a codebase and not having hard coded paths in our run configurations. Rather than using a classpath variable, use a string substitution variable (configured in windows -> preferences -> run/debug -> String Substitution). Set it to the same path as the value of M2_REPO and save. Using the above example if your string substitution variable name was also M2_REPO, the VM Argument would be
-javaagent:${M2_REPO}/org/apache/openjpa/openjpa/2.1.0/openjpa-2.1.0.jar
To be even more clear, I would personally just create an openjpa_2_1_0_agent string substitution variable that went directly to your open jpa jar.