GitLab CI: configure YAML file on java project - java

I have the MyJava.Java that represents my whole project. In the past, I used to execute MyJava.Java in eclipse and working well, but now I want to make the process much more automated and execute it using the GitLab runner pipeline.
my YAML file is very simple just read the MyJava.Java and execute it.
build:
stage: build
only:
- myBranch
tags:
- MyBuilder
image: openjdk:8-jdk
script: javac MyPath/MyJava.java
MyJava has a code and dependency that connected to other files such as this
package myfolder.generator;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Provider;
import java.util.List;
import org.eclipse.emf.common.util.URI;
But whenever I execute the file it shows an error of every import/package such as:
error: package com.google.inject does not exist - import com.google.inject.Inject;
Any hint?
The result of executing the MyJava.Javewill generates a jar file that contains the data that I want. I just mentioned this in case you have another way.

In order to build a java artifact (jar or war) using a CI/CD pipeline you must configure your project to use a dependency manager such as Maven, Gradle or Ant. After you configure your project you will be able to define a build script on the YML file to compile all the necessary dependencies into a java artifact.

Related

How to solve Could not find or load main class?

I would like to build a java application.
System reported error message:
Error: Could not find or load main class com.autoparts.autoeshop.Application
My controller:
package com.autoparts.autoeshop;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
#SpringBootApplication
#EnableJpaAuditing
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
And I have written JAVA_HOME on system property.
Your environment is not completly correct as the JAVA_HOME should point to the installation directory (jdk1.8.0_161) instead of bin and the PATH should include %JAVA_HOME%/bin.
Your trial to compile with javac has been done from the wrong directory, you need to compile when you are in the java directory (including the relative path to the java file like com/autoparts/autoeshop/Application.java). Maybe your project has a build system prepared in the project directory (autoeshop) like Maven (look for a pom.xml) or Gradle (find a build.gradle)? If so, install the required build tool and run it, it will download all required dependencies and compile all the java files for you which is needed before you can run the application using the created jar file (typically found in a target (Maven) or build (Gradle) folder after the build tool ran.
Anyway, if you struggle with this kind of problems you may consider to start with some basic Java or at least Spring Boot tutorials.

import packages in cordova plugin

I'm building a plugin for a PDA3505 device, which must print texts using the integrated printer.
In the plugin's main Java file, I have this import: import com.pda3505.printer.PrinterClassSerialPort;
When I add the plugin to my app and try to make a build, I get this error:
error: package com.pda3505.printer does not exist
import com.pda3505.printer.PrinterClassSerialPort;
Where do I have to put the package for the plugin to work?
If you have .jar files for the PDA SDK, then you have to put it in a folder within the code and add a lib-file entry in the plugin.xml so it's copied to your project.
<lib-file src="src/android/libs/lib.jar"/>

Axiom class cannot be found

I'm trying to compile a simple SOAP client example shipped with Axis2. However the Java compiler cannot find the imports:
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
I have checked my classpath variable is up-to-date on the command line and it includes:
C:\axis2-1.6.1\lib
I have also checked the lib directory contains the required Axiom jars (it does)
axiom-api-1.2.12
axiom-dom-1.2.12
axiom-impl-1.2.12
And that these jars match the package I'm importing (they do). How can I still be getting the error:
error: package org.apache.axiom.om does not exist
?
Asix2 User Guide describes the directory structure and the use of Axis2 tools to prevent the need to set the CLASSPATH environment variable:
The bin directory includes a number of useful scripts. They include
axis2.bat (or axis2.sh), which enables you to easily execute a Java
command without having to manually add all the Axis2 jar files to the
classpath

How do I run JUnit tests from a Windows CMD window when the JUnit class(es) have multiple imports?

Here is my JUnit test class:
package com.bynarystudio.tests.storefront;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import com.bynarystudio.tests.BaseWebTest;
public class SmokeTests extends BaseWebTest {
#Test
public void StoreFrontMegaNavTest(){
webDriver.get(default_homepage);
String source = webDriver.getPageSource();
Assert.assertTrue(source.contains("some text"));
}
}
How do I run this test from the command line? When I try to run it from inside its directory using
java -cp junit.textui.TestRunner SmokeTests.java
I get the following error
Could not find the main class: SmokeTests.java. Program will exit.
I think this has to do with the fact that my classpath is not setup properly. But I have no idea because I'm brand new to Java. Coming from .NET, C#, and Visual Studio, the whole classpath thing makes no sense. Even though I have all my files correctly added to a project in Eclipse (I know because the test runs fine from inside Eclipse), it will absolutely not run or compile from the command line.
First of all you are mixing two things:
First you have to compile the project using javac command. As a result you will get set of .class files (not .java -> this is source code)
Then you can run the code using java command:
java -cp classPath yourpackage.SmokeTests
where:
classPath - is the list of directories or jar files where your compiled classes are, if you jave multiple entries separate them using ";" (windows) or ":"(Linux)
so your classPath can be: -cp .;c:/jars/*;deps
which means your classpath will contain:
current directory
all jar files from c:/jars/*
all jar files from deps directory that is in your working dir
So the full command can will be:
java -cp .;c:/jars/*;deps SmokeTests
yourpackage - is the package of the SmokeTests class, if you do not have package defined in the SmokeTests.java leave this empty

Eclipse Zest plugin source code from github gives manifest.mf error

I am a newbie to eclipse and eclipse plugins. I want to use zest project, with making some specific extentions . So I downloaded eclipse zest plugin source codes from the link below , I am trying to build this project under eclipse 3.7 . But manifest.mf gives error in this lines
org.eclipse.zest.internal.dot.parser.dot,
org.eclipse.zest.internal.dot.parser.dot.impl,
org.eclipse.zest.internal.dot.parser.dot.util,
org.eclipse.zest.internal.dot.parser.parseTreeConstruction,
org.eclipse.zest.internal.dot.parser.parser.antlr,
org.eclipse.zest.internal.dot.parser.parser.antlr.internal,
When i open the packages above, there are some missing files. For example , i see that there is no source of the classes below.
import org.eclipse.zest.internal.dot.parser.dot.AList;
import org.eclipse.zest.internal.dot.parser.dot.AttrList;
import org.eclipse.zest.internal.dot.parser.dot.AttrStmt;
import org.eclipse.zest.internal.dot.parser.dot.Attribute;
import org.eclipse.zest.internal.dot.parser.dot.AttributeType;
import org.eclipse.zest.internal.dot.parser.dot.EdgeRhsNode;
import org.eclipse.zest.internal.dot.parser.dot.EdgeStmtNode;
import org.eclipse.zest.internal.dot.parser.dot.GraphType;
import org.eclipse.zest.internal.dot.parser.dot.MainGraph;
import org.eclipse.zest.internal.dot.parser.dot.NodeId;
import org.eclipse.zest.internal.dot.parser.dot.NodeStmt;
import org.eclipse.zest.internal.dot.parser.dot.Stmt;
import org.eclipse.zest.internal.dot.parser.dot.Subgraph;
import org.eclipse.zest.internal.dot.parser.dot.util.DotSwitch;
I am not able to build from source ,-I think- since there are some missing source codes in git link.
do you have any solutions thank you .
The dot parser is an Xtext project that needs source code generated. At this point, it needs two manual steps:
Create a src-gen folder in the root folder of org.eclipse.zest.dot.core - this will become a source folder. Git does not upload empty folders in git.
Similarly create a src-gen folder in org.eclipse.zest.dot.ui.
Execute the org.eclipse.zest.dot.core/src/org/eclipse/zest/internal/dot/parser/GenerateDot.mwe2 workflow file (Run as/MWE2 workflow). This will generate all necessary code. If you did not create the source folders, this step would fail with a really cryptic error message.

Categories