Self executing jar with Plain Java API
Hi,
I've developed a plain java class which launch a build definition, and it works fine using RTC eclipse run configuration. I've tried to export my class using built-in Executable jar export using the same run configuration.
But when I try to run my jar from command line I've got an exception:
when startBuild is my class and login is a login method copied from snippet1:
It seems that error is on TeamPlatform.getTeamRepositoryService().getTeamRepository(REPOSITORY_ADDRESS) line, but the things is that running on client it works perfectly.
Any idea?
I've developed a plain java class which launch a build definition, and it works fine using RTC eclipse run configuration. I've tried to export my class using built-in Executable jar export using the same run configuration.
But when I try to run my jar from command line I've got an exception:
Exception in thread "main" java.lang.ExceptionInInitializerError
at java.lang.J9VMInternals.initialize(J9VMInternals.java:218)
at com.ibm.team.repository.client.internal.TeamRepository.<init>(TeamRepository.java:387)
at com.ibm.team.repository.client.internal.TeamRepositoryService.createSharedTeamRepository(TeamRepositoryService.java:366)
at com.ibm.team.repository.client.internal.TeamRepositoryService.getTeamRepository(TeamRepositoryService.java:91)
at com.ibm.team.repository.client.internal.TeamRepositoryService.getTeamRepository(TeamRepositoryService.java:110)
at it.nexen.test.plain.StartBuild.login(StartBuild.java:49)
at it.nexen.test.plain.StartBuild.main(StartBuild.java:27)
Caused by: java.lang.IllegalArgumentException: The type name Contributor and the namespace URI com.ibm.team.repository do not resolve to an IItemType.
at com.ibm.team.repository.common.internal.querypath.AbstractQueryPathModel$Implementation.getItemType(AbstractQueryPathModel.java:190)
at com.ibm.team.repository.common.query.IQuery$Factory.newInstance(IQuery.java:92)
at com.ibm.team.repository.client.internal.ContributorManager.createAllC
ontributorsQuery(ContributorManager.java:57)
at com.ibm.team.repository.client.internal.ContributorManager.<clinit>(ContributorManager.java:45)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:196)
... 6 more
when startBuild is my class and login is a login method copied from snippet1:
public static ITeamRepository login() throws TeamRepositoryException {
ITeamRepository repository = TeamPlatform.getTeamRepositoryService().getTeamRepository(REPOSITORY_ADDRESS);
repository.registerLoginHandler(new ITeamRepository.ILoginHandler() {
public ILoginInfo challenge(ITeamRepository repository) {
return new ILoginInfo() {
public String getUserId() {
return USER_AND_PASSWORD;
}
public String getPassword() {
//"return USER_AND_PASSWORD;
return "password";
}
};
}
});
System.out.println("Contacting " + repository.getRepositoryURI() + "...");
repository.login(null);
System.out.println("Connected");
return repository;
}
It seems that error is on TeamPlatform.getTeamRepositoryService().getTeamRepository(REPOSITORY_ADDRESS) line, but the things is that running on client it works perfectly.
Any idea?
Accepted answer
I too faced same issue, resolved by changing the way jar file got generated from eclipse client. Followed the steps mentioned below
Step 1: Right on Project , select export
Step 2 : In export wizard, page 1, select the option
Java > Runnable Jar file
Step 3 : In export wizard, page 2,
a) Launch configuration : select the Main Class
b) Specify Export Destination e.g C:\Temp
c) Library handling
use the option : Copy required libraries into a sub-folder next to the generated JAR
Now to verify the jar, Go to export destination e.g. C:\Temp
use the command
# java -jar <jarfilename.jar>
6 other answers
Are you calling com.ibm.team.repository.client.TeamPlatform.startup?
If so, and it's still not working, see 76455: Error running standalone java app.
If so, and it's still not working, see 76455: Error running standalone java app.
Your jar and the 'API' jars (I assume you mean the plug-in jars from Jazz/RTC) all need to be on your classpath, but you shouldn't need to use -Djava.ext.dirs, or have .class files outside of a jar.
I'm not sure what you mean by 'as the compiled executable jar is something like 23Mb'. Are you adding the Jazz/RTC jars to an enclosing jar? Normally they're all at the same level.
For an example of the kind of organization you can have for a standalone Java client to RTC, see the buildengine/buildtoolkit directory in the Build System Toolkit. All the jars here are added to the classpath via Ant's -lib argument. The entry-point is typically one of the Ant tasks in the com.ibm.team.build.toolkit jar.
I'm not sure what you mean by 'as the compiled executable jar is something like 23Mb'. Are you adding the Jazz/RTC jars to an enclosing jar? Normally they're all at the same level.
For an example of the kind of organization you can have for a standalone Java client to RTC, see the buildengine/buildtoolkit directory in the Build System Toolkit. All the jars here are added to the classpath via Ant's -lib argument. The entry-point is typically one of the Ant tasks in the com.ibm.team.build.toolkit jar.
I'm not very used with executables jar and probably I'm doing something conceptually wrong. But what I'd like to have is a jar which I can execute directly using "java -jar jarName".
In jar I've created in my test I can't do this because I've always error on finding class related to plug-in jars of PlainAPI and I resolve this only using -Djava.ext.dirs option (only setting the CLASSPATH env variable doesn't run).
I've tried to put all these java into my jar (and so I have the large amount of Mb), using Class-Path reference on Manifest and I've also tried to use build-in Eclipse wizard to create executable jar and it takes all api jar and put their classes into my jar (as I've develped them).
In both cases I've always the same missing class error.
I agree that this is not the correct way, because I've to rebuild my jar every time API jars will change, but I would like to have this kind of option.
In jar I've created in my test I can't do this because I've always error on finding class related to plug-in jars of PlainAPI and I resolve this only using -Djava.ext.dirs option (only setting the CLASSPATH env variable doesn't run).
I've tried to put all these java into my jar (and so I have the large amount of Mb), using Class-Path reference on Manifest and I've also tried to use build-in Eclipse wizard to create executable jar and it takes all api jar and put their classes into my jar (as I've develped them).
In both cases I've always the same missing class error.
I agree that this is not the correct way, because I've to rebuild my jar every time API jars will change, but I would like to have this kind of option.
Have you considered running it as an Eclipse/OSGi application instead of standalone Java? For example, the build engine process, jbe, runs this way.
It can then be invoked with a simple command (jbe, which is simply eclipsec.exe renamed). Or you can use: java -jar plugins/{equinox launcher jar}
For more details, see "How can I run the build engine on a platform other than Windows or Linux?" at:
https://jazz.net/wiki/bin/view/Main/BuildFAQ#OtherPlatforms
It can then be invoked with a simple command (jbe, which is simply eclipsec.exe renamed). Or you can use: java -jar plugins/{equinox launcher jar}
For more details, see "How can I run the build engine on a platform other than Windows or Linux?" at:
https://jazz.net/wiki/bin/view/Main/BuildFAQ#OtherPlatforms